-
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 grammar first then you can write a paragraph. In coding, you can think CP programming as grammar learning and frameworks as paragraph writing! When you know grammar 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
-
You will find Interview problems much much easier if you do CP. Problem solving skill is required in interviews and CP is the best and most exciting way to learn problem solving.
-
"Competitive programming is recognized and supported by several multinational software and Internet companies, such as Google and Meta (Facebook). There are several organizations who host programming competitions on a regular basis." - Wikipedia
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!
-
-
Not everyone has the privilege to do the things that they enjoy to do. If you have that privilege, then its really cool. But most of the people don't have that privilege. So "Instead of doing things you enjoy, learn to enjoy the things you do". And CP is one of the things that you can easily fall in love with.
-
If you find yourself approaching thing too seriously, like its no fun playing a game if you take it "too seriously". So if you want to have fun, you should switch to approching things sincerely, like you are still gonna give it all, but you are gonna recognize that this is a game and you are gonna try and enjoy yourself while doing it. This philosophy also applies in CP. Watch this for more.
-
Most Competitive Programmers (more than 95%) use C++ mostly because its quite faster than other languages and it has some great built-in libraries(Standard Template Library (STL)) to ease your life. There are also many other reasons for using C++.
You can also use other languages too but for CP C++ is better. Languages are just tools and it doesn't take more than a few days to understand the basics of a language.
Note that you don't have to be master in C++ to start you CP journey. If you know the basics i.e. variables, data types, operators, conditions, functions and loops, then you are ready to start CP. You can learn them from here or from any of your favorite youtube channels.
-
IDEs are where you will write your codes. You can use Sublime Text, Codeblocks, VS Code or any other IDE that you like.
I personally use Sublime Text. Check this to set up C++ in Sublime Text for Competitive Programming. Check this to set up useful tools for Sublime Text.
Check this to setup C, C++, Java, Python in Visual Studio Code for Competitive Programming.
-
The most famous CP platform is Codeforces. Check this to know about more platforms.
-
Details about problem statements, how contests work and the rating system on Codeforces (and a few other platforms)
Check this to get a detailed understanding of whats in a problem, what is meant by different verdicts (AC, WA, TLE, MLE, CE etc) and how contests work.
-
Most of the problems have editorials/tutorials. The tutorial link is normally attached to the problem statement. In particular, on Codeforces, you can find the link to the tutorial at the lower right side of the problem statement.
Also, join this discord server(if you are from Bangladesh) to get help. Link: Bangladesh CP Server
-
Check this to check solutions for a specific problem on Codeforces.
For other platforms the way is similar. Just go the submissions page for that problem and click on the ID of the submission.
You can follow other users on Codeforces and make them friends (click the star button on the right of the username on CF) and check their solutions using the "friends only" button. I personally like the coding styles of the following users:
-
- 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/tutorial 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.
-
Kidlin's law : If you can write the problem down clearly then the matter is already half solved.
This is also the same here in CP. First understand what the problem asks you to do. Then proceed to solve it. If you understand it correctly, then you are half done. So don't start solving without understanding what the problem demands.
-
Get familiar with problem solving by solving these problems. You won't need to know anything other than basics of a language to solve them.
Goal: Solve at least 30 problems in total from the following contests. -
Credit: @MehediMubin, @tahmidarefin and @Tofayel and me
Smash me
1. Problem AEditorial: link
Code(C++)
#include<bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << a * b << '\n'; return 0; }
2. Problem B
Editorial: link
Code(C++)
#include<bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << max(0, b - a + 1) << '\n'; return 0; }
3. Problem C
Editorial: link
Code(C++)
#include<bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << max({a + (a - 1), b + (b - 1), a + b}) << '\n'; return 0; }
4. Problem D
Editorial: link
Code(C++)
#include<bits/stdc++.h> using namespace std; int main() { double d; cin >> d; cout << round(d) << '\n'; return 0; }
5. Problem E
Editorial: link
Code(C++)
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n < 10) cout << "000" << n << '\n'; else if (n < 100) cout << "00" << n << '\n'; else if (n < 1000) cout << "0" << n << '\n'; else cout << n << '\n'; return 0; }
6. Problem F
Editorial: link
Code(C++)
#include<bits/stdc++.h> using namespace std; int main() { int a, b, t; cin >> a >> b >> t; cout << t / a * b << '\n'; return 0; }
7. Problem G
Editorial: link
Code(C++)
#include<iostream> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; if((a - 1) / c == b / c) cout << -1 << '\n'; else cout << c * (b / c) << '\n'; return 0; }
8. Problem H
Editorial: link
Code(C++)
#include<iostream> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; for(int i = 0; i <= 5000; i++){ for(int j = 0; j <= 5000; j++){ if(i * a + j * b == c){ cout << "Yes" << '\n'; return 0; } } } cout << "No" << '\n'; return 0; }
9. Problem I
Editorial: link
Code(C++)
#include<iostream> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; cout << ((a * a + b * b) < c*c ? "Yes" : "No") <<'\n'; return 0; }
10. Problem J
Editorial: link
Code(C++)
#include<iostream> #include<iomanip> using namespace std; int main(){ double a, b, ans; cin >> a >> b; ans = (a - b) / a * 100.0; cout << fixed << setprecision(3) << ans << '\n'; return 0; }
11. Problem K
Editorial: link
Code(C++)
#include<iostream> using namespace std; int main(){ int n, m; cin >> n >> m; cout << (n == m ? "Yes" : "No") << '\n'; return 0; }
12. Problem L
Editorial: link
Code(C++)
#include<iostream> using namespace std; int main(){ long long n; cin >> n; cout << 25 << '\n'; return 0; }
13. Problem M
Editorial: link
Code(C++)
#include<bits/stdc++.h> using namespace std; int main(){ int S, T; cin >> S >> T; int cnt = 0; for(int a = 0; a <= S; a++){ for(int b = 0; a+b <= S; b++){ for(int c = 0; a+b+c <= S; c++){ if(a*b*c <= T) cnt++; } } } cout << cnt << endl; }
14. Problem N
Editorial: link
Code(C++)
#include <iostream> using namespace std; typedef long long ll; int T; ll N; int main() { cin >> T; for (int t = 0; t < T; t++) { cin >> N; ll power = 1; while (2 * power <= N) power *= 2; cout << N*(N + 1) / 2 - 2 * (power * 2 - 1) << "\n"; } return 0; }
15. Problem O
Editorial: link
Code(C++)
#include<bits/stdc++.h> using namespace std; int main() { int k, s; cin >> k >> s; int count = 0; for (int x = 0; x <= k; x++) { for (int y = 0; y <= k; y++) { int z = s - x - y; if (z >= 0 and z <= k) { count++; } } } cout << count << '\n'; return 0; }
16. Problem P
Editorial: link
Code(C++)
#include<bits/stdc++.h> using namespace std; typedef long long ll; string s; int main() { cin.sync_with_stdio(0); int sum = 0; cin >> s; for (int i = 0; i < s.size(); i++) sum += s[i] - '0'; int ans = 1; if (s.size() == 1) ans = 0; while (sum > 9) { int temp = sum, newsum = 0; while (temp) { newsum += temp % 10; temp /= 10; } sum = newsum; ans++; } cout << ans << endl; return 0; }
17. Problem Q
Editorial: link
Code(C++)
#include <iostream> #include <cstdio> using namespace std; int fact(int n) { int r = 0; for(int i = 2; i * i <= n; ++i) { if(n % i == 0) { r++; while(n % i == 0) n /= i; } } if(n > 1) r++; return r; } int main() { int n, c = 0; cin >> n; for(int i = 1; i <= n; ++i) { if(fact(i) == 2) c++; } cout << c << endl; return 0; }
18. Problem R
Editorial: link
Code(C++)
#include <iostream> using namespace std; int main() { int y; cin >> y; while (true) { y += 1; int a = y / 1000; int b = y / 100 % 10; int c = y / 10 % 10; int d = y % 10; if (a != b && a != c && a != d && b != c && b != d && c != d) { break; } } cout << y << endl; return 0; }
REMEMBER THAT SOLVING MORE PROBLEMS IS THE KEY
-
Check this if you want. It contains everything.
-
- Exercise (at least running) and drink more water. It will surpirisingly boost up your learning capability.
- Getting AC is not the final goal, learning something new is the final goal. Exactly for this reason, people solve thousands of problems but can't get better. You need to solve harder problems than your current level so that you can learn something new by solving that problem. Also, after you solve a problem, try to do it more efficiently if possible, look at others solutions. This way you will learn better and become better faster in the long run.
- After solving a problem, think about why your way of thinking was not optimal. This is important too.
- SOLVE MORE PROBLEMS.
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.
-
If you want a complete guideline like this for EVERYTHING about CP and you are from Bangladesh, then you can check out my academy and enroll in some courses that fits you well.
Link: YouKn0wWho Academy.
Actually the whole part of this repo till now is taken from a single class from one of my academy courses!
-
- 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.
-
- 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 value?
- 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) instead of: 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.
Also, remember to exercise and drink more water. It helps a lot.

