Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя SayedAulia

Автор SayedAulia, история, 15 месяцев назад, По-английски

Throughout my short Competitive Programming journey one particular problem that I kept facing, which I think is the main reason of my slow progress is that despite sometimes getting the full ideas to a problem rather quickly, I would still spend 10 times longer trying implementing it until getting the test sample right let alone getting an AC.

I think this is a key factor why some newbies competitive programmer (including myself) progress poorly despite having some mathematical and algorithmic intuition (I am not claiming that I have such good intuition). They'll get burnt out implementing it properly and most of the times wasted their time that could have been used to advanced to another problems.

I believe that the skill of getting the key observation and actually implementing it right and clean are two different (yet not separated) skill. The question I want to ask for the more experienced competitive programmer are:

• Have you experienced similar case long time ago?

• If you have, do you have any tips on how to improve implementation?

• What to do if you cannot implement your solution after a long period of times? Should you move on?

Here is me trying to implement the solution for [problem:https://codeforces.me/contest/1294/problem/F] for hours after getting the the full ideas similar to the editorial.

 Source: 211724504

Pain.

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

»
15 месяцев назад, # |
Rev. 2   Проголосовать: нравится +16 Проголосовать: не нравится

As the best Brazilian coder tfg would to say: "Learn how to code". A high level hint I could give is try to think of the implementation of your idea before rushing into coding. It's better to spend 5 or even 10 minutes thinking of how to implement a complex function than to code it poorly in 3 minutes and then ending up spending more 20 minutes debugging. Also, it takes years to improve coding. (At least that was the case for me) Don't assume you will magically improve. It takes time :)

  • »
    »
    15 месяцев назад, # ^ |
    Rev. 4   Проголосовать: нравится +23 Проголосовать: не нравится

    The context of when/why I said that is different.

    Someone asked what they should learn in order to do better in ICPC. Then I said "Learn how to code" and explained further that if you can't implement your ideas in a reasonable time during the "easy problem" phase there's no use for advanced knowledge of data structures/algorithms so instead of learning those because "it's ICPC" it's better to practice problem solving and implementation.

    Anyway since you pinged me I might as well throw my 2 cents in this thread. Here come some tips:

    1. Learn from others. Discussing problems with others is a very good source to know what you're doing wrong. I learned a lot in my first year from people that were more experienced than me (even though I was higher rated by 500+) simply because they had alternative ideas in problems where I overkilled and that left a huge mark in the way I approach implementing. Also good is looking at other people's code for problems that you struggled with implementing as it also might teach you some neat implementation tricks.

    2. Think before implementing. I see a lot of people jumping straight into implementation when they have some idea but I think that's a bad habit. Unless you're very short on time in a contest and you want to throw a hail mary submission, you should think a bit after you have some idea in order to CONFIRM that your idea is correct/check that you actually understand your idea and RETHINK to see if there's a better way to solve the problem. This is a necessary skill in ICPC where PC time is shared, so you have more time to do this, but even in solo contests thinking for 2-5 minutes before implementing might save you 10-20 minutes further on by giving you better implementation/removing necessity of stopping to think or change big parts of code while coding/covering potential bugs before they happen. An additional benefit is that thinking about alternatives actively gives you more immediate options when solving similar problems in the future. I think that even if you code using 1 finger in each hand, if you understand your solution well enough before coding you should almost never spend more than 20 minutes implementing a solution for a div2ABC problem.

    TLDR: implementation troubles more often than not come due to you having a bad idea before coding or not even understanding your own ideas, so learn from others by comparing your solution to other people's and think before coding in order to find a way to implement it nicer and/or in order to understand your ideas more deeply.

    Also it goes without saying: solve a ton of problems. A programming language kind of is a language, I think there's no way to be fluent in programming if you haven't programmed a lot.

»
15 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

I'd assume you would want help with that problem, right? Anyway, here is a test case where your code fails:

Input:
7
2 3
3 4
1 5
3 1
6 3
7 4

Your Output:
7
7 5 2

Correct Output (for example):
5
7 5 2

Here is a picture of the tree in question:

The red edges are the ones on paths between $$$2$$$, $$$5$$$ and $$$7$$$. You can see that there are $$$5$$$ edges between the chosen nodes (which is also optimal), but your code outputs $$$7$$$.

»
15 месяцев назад, # |
Rev. 2   Проголосовать: нравится +12 Проголосовать: не нравится

My two cents :

  • Try to solve easier problem first until you "get" the intuition to solve them

I notice that in your Codeforces profile, you only solved 90+ problems until this point. Assuming you don't have practices in other OJ account, then you can get used to the easier problem first and get used to implement them. But make sure not to get "comfortable" solving many 800s problems for the sake of "implementation practice". Try to mix the range of difficulties

Back then, my method was "if I can't solve C in contest, then I keep practicing to solve lots of problem Cs first until I get used to it"

  • Keep your local coding environment "convenient" for trunning, testing, debugging etc.

While the definition of "convenient" might ne different for everyone, but having a comfortable environment is helpful

Mine is using a VS Code with CP Helper and Code Runner. This helps me for a quick testing and debugging

  • In case of your solution keeps failing and not getting accepted, finding a counter cases that makes your program fails helps too. I realized it's kinda hard to do so, but nevertheless it's a good thing to try when you got stuck since at least you know where to start when you found one