death_bringer's blog

By death_bringer, 2 years ago, In English

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:

  1. 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?
  2. 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?
  3. 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?
  4. 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.
  5. 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?
  6. 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.
  • Vote: I like it
  • +14
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
Rev. 2   Vote: I like it -6 Vote: I do not like it
  1. I don't really sure, but I think it can make the coding speed faster (don't have to write LONG templates) and avoid some stupid mistakes.
  2. sorry but I don't know.
  3. DON'T DO THAT unless you are very aware of what it can cause. Not only may it cause MLE, but it also slows down the code.
  4. Just solve more problems and gain experience maybe.
  5. sorry but I am not sure.
  6. same as 4. And at the same time, it's a good idea to write something to sum up.

Sorry for unclear words on previous version.

»
2 years ago, # |
Rev. 2   Vote: I like it +12 Vote: I do not like it

3) Don't listen comment above, it's completely fine while you understand what are you doing.

»
2 years ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it

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), not lower_bound(s.begin(), s.end(), x), otherwise you will get TLE

»
2 years ago, # |
  Vote: I like it +22 Vote: I do not like it

I guess I've been on Codeforces long enough to answer some of these questions, so here we go:

  1. 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.

  2. 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.

  3. 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 :)

  4. 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.

  5. 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.

  6. 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).

»
2 years ago, # |
  Vote: I like it +9 Vote: I do not like it
  1. 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.

  2. (not qualified to answer)

  3. 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).

  4. 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 :).

  5. I do this all the time, but I imagine that it's detrimental.

  6. Shoutout to galen_colin and zscoder for their amazing DP tutorials!