n1cat's blog

By n1cat, history, 13 months ago, In English

Today, I submitted a code on Codeforces, and it got a WA on test 2. When I looked up what is wrong with my code, 312665141 it says "wrong answer 5th numbers differ — expected: '3', found: '6' ", but when I try my code on compiler, it gave me actual value. So, how can I fix it?

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

| Write comment?
»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Please check if there are undefined behaviors in your code.

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

mango mango

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

you didn't reset the used array, maybe that is the only issue

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    instead of this, I used a pointer for every testcase, which works for graph problems and helps to decrease time complexity

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      The problem with using arrays to track whether an index has been "used" is that, instead of using bool, you should mark the index with a variable (e.g., TIME or c in your case) using int or long long.

      Your submission gets TL verdict after applying the fix.

      submission