- ### The Ultimate Question: Why should I start Competitive Programming?
Well, I believe that the ultimate goal of my existence is to be happy. And I have learned from many well-established people that getting a great job or being famous or other common stereotypical goals won't make you happy as when you get used to those they become meaningless.
I think happiness is living your present with excitement.
That being said, now your main goal is to find something that will make you happy. There are lots of things you can do like being a musician or an artist etc. For me it was CP. I can lose myself into CP for hours and hours and still hold my excitement. A good contest is enough to make my day.
Man, I am not saying that you have to choose CP too. Find anything that suits you well, delve into that and maybe you will find peace.
Because I wanna spend my precious time on something so that in the end I can say with Heisenberg, "I did it for me. I liked it, I was good at it, and I was really... I was alive".
Let's discuss something if you think CP is the thing that you wanna do.
Many of us set this goal like I wanna be red and continuously looking at the goal and not enjoying our current hard works. I am not red but I can guarantee myself that when I will be red I will be happy for a day or two and will get used to it. So what was my 3-4 years of hard work all about? Just a day of excitement? I don't believe in so. Wouldn't it be great if I could live those 3-4 years of my life with excitement? Well yes. This is what I am currently doing. I am living in the present, working hard and whether I become successful or not I will still be happy as I was alive throughout the whole process and lived my life to the fullest.
May you find that something that you have been looking for throughout your life!
- Create a topic list(every possible category, from easy to advanced).
- Select a topic.
- Learn the topic.
- Solve lots of problems about that topic.
- Go to ii.
And of course, participate in every possible contests in every online judge.
How to Practice a Problem?
- First of all, you should try to solve it by yourself.
- At the first glance, it may look like you have no idea what that random alien-made problem is asking you to do. But take your time. Always try to solve the problem using brute force. After that try to make your solution more efficient.
- Ok, so still you have no idea on how to solve the problem? Try to look at it from a whole new angle.
- "Keep trying while you have new ideas, then look up the editorial after 15+ minutes of being completely stuck." - Errichto
- To be more precise, if you think you are getting into the solution, then take more time and try to solve it. But if you have no clue on how to solve it, then what is the point of wasting your valuable time? It will only slow down your improvement process.
- Time to implement the problem. Try not to use any unnecessary macros. Try to make it more readable. It will help you debugging the solution.
- After that read implementations of some skilled users (searching for some useful tricks or really nice implementations). This part is really important which will significantly improve your skill.
- If the problem uses a new idea/trick/algorithm which is a classic one i.e. it might be helpful in future then try to write that down so that in future you can easily access it.
The Art of Debugging
- Run with n=1.
- Check overflow(long long vs int).
- Check all array bounds.
- Check if m, n aren’t misused.
- Printed enough new lines or extra new lines?
- Make sure output format is right(including YES/NO vs Yes/No or
newline vs spaces).
- Have you cleared the vectors ?
- Make sure two ints aren’t multiplied to get a long long.
- Output enough digits after decimal point.
- Check the constraints again.
- When using multiple dfs recursions check if inside one dfs another dfs
is called or not.
- Shouldn't you print the case number?
- Are you using the correct mod value?
- "I spent a lot of my time debugging my solution without any success,
after the contest I discovered that the obstacles in the input is 'x'
(small one) while I was thinking it was 'X' (capital), I lost a bronze
medal because of it :(" - kingofnumbers
- Set or multiset?
- Different Variables with the same name?
- Inside 2d loop are you using i++ instead of j++?
- Are you using ceil function? Then remove it!
- Is inf large enough?
- For multiple queries are you returning 0 inside the queries?
- For max and min have you initialized the values by a good enough
- Are you using the local variable of the same name when global variable was
required to be used?
- "Declared a counter of type char instead of int , resulted in passing of
pretests and failing of system test. :)" - A random CF user
- "I subtracted 1 in a for loop from v.size(). Guess what happened when
the input vector is empty?" - A random CF user
- "for (int i = n - 1; i--; i >= 0)
for (int i = n - 1; i >= 0; i--)
It passed pretests and failed systests" - A random CF user
- Are you using memset correctly?
- Use bool operators using brackets. Beware!!! E.g. ans = ans + k == 0 vs ans = ans + (k == 0).
- Have you deleted debug(x) lines? It might get you TLE!
- It may be scanf("%d" , x). where &x is missing.
- Instead of printing NO printed N0. (with a zero).
- Are you erasing values from a set or an stl while parallelly traversing
the elements of the stl? Please don’t. This is not nice!
- Don't use scanf or printf while using ios_base.
- Still have no idea? Try to recode from scratch or see others solutions.
Topic List (As you are feeling lazy to collect them by yourself!)