ay2306's blog

By ay2306, history, 6 years ago, In English

I was solving a question on codeforces. Sample test case are giving me correct answer in terminal but it is different in codeforces submission.

Link to submission. My terminal gives me a correct answer of

yes 1 3

but it is no in codeforces. How do I debug in such a situation?

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

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

Look for undefined behavior. In your case, it should be this line: for(int i; i < n; ++i){. You need to initialize the counter first. Corrected, it passes through 6 tests: 39749555.