Hi Codeforces, At this point, I'm doing competitive programming for about a year on and off Codefores. When I started out I had a lot of questions about a lot of things but thought to myself that experience would teach me. But at this 1-year mark, I still don't know a lot of things that even new programmers do. Here's a list of questions:
- Why use such a big template with so many macros and functions? I have solved problems till 1800 rating but never felt a need but nowadays every solution I see for hacking is using these templates. Is there any reason behind them?
- How to be friends with authors (to be a tester)? I spend a lot of time on codeforces doing stuff like stalking good programmers, checking out top comments and blogs, and rarely messaging some people to get help but how do people just become friends on codeforces?
- A lot of time I get a
WA
because of integer overflow. So, I want to use the biggest possible data type for all variables. Is that ok or it can cause problems? - Many people on codeforces know a lot about how a particular piece of code or function can slow down your code. How can I know it because I waste a lot of time on things I didn't know and had no way of knowing on my own? Like endl is very slow and can cause your
TLE
and in-built sort shouldn't give try condition(a,b)
and(b,a)
comparison. - I generally don't check the editorials of problems but check out the test cases on which my solutions have failed. Is it bad because recently my frequency of submitting a wrong solution during a contest is increased?
- I'm not getting better at DP and most problems that were on my rating but I'm not able to solve are DP-related. I did cses problem set and its book. DP contest at AtCoder but I think I'm only learning and remembering types of problems in DP but not how to approach a new DP problem.
MLE
, but it also slows down the code.Sorry for unclear words on previous version.
3) Don't listen comment above, it's completely fine while you understand what are you doing.
4) Just practise :) I can remember about one tricky thing — when you want to use lower_bound on set (many times), you should write it like
s.lower_bound(x)
, notlower_bound(s.begin(), s.end(), x)
, otherwise you will get TLEI guess I've been on Codeforces long enough to answer some of these questions, so here we go:
I think it's because of multiple reasons: some people try to maximize their convenience to the point where they forget they need to actually practice, while some people just like huge templates. I used to use huge templates at some point too (but that's just because I saw some high-rated person use them too) -- I guess bad practices just spread like wildfire.
Pretty much how you make friends/acquaintances irl -- talk to them. Join online communities (like competitive programming servers on Discord and so on) and talk to people about stuff. Or just comment and reply on commments.
Very controversial question. I personally avoid it, but when I'm not sure, I use the largest possible datatype. I prefer not using gimmicks such as
#define int long long
(though I have used it in the past a lot), but a lot of people will say that I should use it if I want to be higher rated. Up to you to decide :)Read documentation, write and submit code, and profile your code when you really want to know. There's no way other than experience that I know of.
I personally feel looking at test cases is kind of bad, but it's again up to you. An important skill for competitive programming is to come up with corner cases yourself (which is a subset of testing and debugging your code), so you're essentially depriving yourself of the opportunity to develop such a skill.
Learn recursion and how DP is just recursion, and think in terms of states (which are basically subproblems, which is basically thinking in terms of recursion).
As a former large template lover, I mostly saw highly rated people like Benq use massive templates, so I figured it was a good idea. I've stopped with the massive templates now, because it made my code unreadable.
(not qualified to answer)
They're slower, but not by much. Unless you're trying to cheese, I see no reason why not to (unless you're vying for readability).
Short answer is practice. Once, my code was TLEing and I was super confused why, so I asked on Codeforces, and someone helped me out and taught me the \n vs \endl trick. If you're super confused, there's a forum for a reason :).
I do this all the time, but I imagine that it's detrimental.
Shoutout to galen_colin and zscoder for their amazing DP tutorials!