ArisugawaSakura's blog

By ArisugawaSakura, history, 2 months ago, In English

What to do when solution’s idea is right, but code fails on large test. How to find the bug?

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

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

You should consider your previous experience with bugs and how to fix them. For example:

  1. Overflow (long long VS int)
  2. Using the wrong mod (998244353 vs 1000000007)
  3. ...

I also recommend using assert function as possible as you can so you know if your code works properly or not. In this case, when I get the wrong answer verdict I am almost sure that my solution is not correct and the mistake is not about my bad implementation.

When you can't figure out where the bug is you can do stress testing on your solution, if you have enough time, to get a test case that makes your solution fail.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Do a stress test and try to find a smaller test case which fails.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Top-to-down approach

Start from the top from where the program starts and comment the rest of cold below. Do a test on it debug it and go on to the next part. uncomment some parts and test them and so on..

Your Free Waifu

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

also check if vectors/other data structures has elements left before trying to query, i RTE'd 5 times on a problem once because i forgot to check if the vector is empty or not before getting the value of v.back()