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

Автор fuck_rating, история, 3 года назад, По-английски

i was solving a problem on atcoder and my submission is giving WA

although my solution is giving correct output on my computer. strange thing is that it is giving wrong answer even on sample test cases which are surely correct. can anyone mention the reason or any issue from my side

submission link — https://atcoder.jp/contests/abc194/submissions/51686326

input tc link — https://www.dropbox.com/sh/nx3tnilzqz7df8a/AADjf_qIms_cFXcQMAhArzKma/ABC194/E/in?dl=0

correct output link — https://www.dropbox.com/sh/nx3tnilzqz7df8a/AABQc4d2ofLTo0bmoMNq75C5a/ABC194/E/out?dl=0

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

»
3 года назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Happens with me on codeforces when I access illegal indexes. Recheck the array indices which you are accessing.

Edit - You are doing mp[a[i-m-1]]--; in your for loop. What happens when i is less than m-1 ? You are accessing negative indices. Your compiler won't give error, but online judges will. You need to correct that.

»
3 года назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Out of bound index leads to undefined behaviour. In your code, i — m — 1 is obviously not correct and could potentially get negative index. Tip: enable address sanitizer to detect such issue when compile.