- ### 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".
So what kinda benefits you will get by doing CP?
- Fun and excitement(tons of it).
- "Competitive programming builds the basics in you. You became so expert in coding anything that learning framework then becomes very very easy task. Because when you learn to read the codes of hard or advance algorithms, what can be more complex than those?
CP programming makes you versatile, so you can move from any stack to other. But when you only learn specific framework or stack, your knowledge gets bounded.
You can compare learning any natural language with this. Lets say you want to learn german/english. You need to learn grammer first then you can write a paragraph. In coding, you can think CP programming as grammer learning and frameworks as paragraph writing! When you know grammer you can write paragraph on any topic.
Even after a good or average (not the best) career in CP, you will find database, distributed system, machine learning topics very much understandable to you."- Raihat Zaman Neloy
- Career Opportunities.
- and many more...
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!
Getting into Competitive Programming
Note: If your Codeforces rating is not at least 1600 then the aftermentioned topicwise practice is not needed, just learn basic stuffs and follow the tutorial linked above.
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." - Kamil Debowski
- 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.
How to do Topicwise Practice?
1. Create a topic list(every possible category, from easy to advanced).
2. Select a topic.
3. Learn the topic.
4. Solve lots of problems about that topic.
5. Go to ii.
And of course, participate in every possible contests in every online judge.
Topic List (As you are feeling lazy to collect them by yourself!)
- The Ultimate Topic List (with Resources, Problems and Templates)
- ### Code Library
- Almost all the important templates that you will need in CP
- ### FAQ
- Solve Problems!
- Regarding Interviews and Jobs
- CP or Development?
- I need Advice
- When will I be a good CPer?
- ### 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.
- ### Stress Testing
- Find a counter-test
Also, remember to exercise and drink more water. It helps a lot.
Good luck .