Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

TheScrasse's blog

By TheScrasse, history, 6 weeks ago, In English,

Hello,
I noticed that I often overcomplicate problems, hence my codes are often very long and I lose precious time during contests.
Some examples:
70077990 I wrote a sliding window minimum, but it wasn't necessary since $$$O(n^2)$$$ is fast enough with those constraints.
79841706 I found a solution that required too much memory. My "optimization" is 90 lines long. That problem can be solved in 30 lines.
79880987 I used a dfs and a 0-1 bfs (120 lines), a single bfs was enough.
Overall, I find difficult to improve a solution that seems already feasible.
Could you give some advice about how to stop overcomplicating problems?

 
 
 
 
  • Vote: I like it
  • +40
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it +67 Vote: I do not like it

I wish I can be in a stage where I can overcomplicate problems xD.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Again...
81543406 I thought that the optimal vacation didn't have to finish at the end of a month.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +43 Vote: I do not like it

    For me it was because I used to jump directly to the coding part with not so clear idea. Now I give time to furnish my thoughts before attempting. Here is my code (81529899) for D, you can see it is well structured.

    Note: I am not so experienced, this might not be the true cause for hard problems.

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

I think you are not generalizing the problems well.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Well... How to know if a problem can be generalized or not? Some problems are implementation heavy, so a long code cannot be improved, and you lose time if you try to generalize.

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

From my experience, I would suggest that after solving a problem you check other solutions which might be simpler. Eventually you will jump down to simpler approaches.

Another key method which was helpful for me, is to think about your solution for a couple of minutes before coding. I used to get excited once I find an approach and a couple of mins could have saved like 50 lines or sth.