eigenvalue's blog

By eigenvalue, history, 4 months ago, In English,

Hi codeforces,

I was attempting to solve the KMP problem below, but I'm failing on testcase 3.When I run the testcase locally, I am getting the correct answer on my machine. Could somebody help spot the bug that is probably causing undefined behaviour?

Problem: http://codeforces.com/contest/471/problem/D Solution: http://codeforces.com/contest/471/submission/31585259

  • Vote: I like it  
  • -11
  • Vote: I do not like it  

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

I ran the code on my system and it gave 1 on your third test case which means your code output is system dependent which happens because you are accessing memory not allocated to your variables. Looking roughly through the code I'd say check the "pattern[q+1]" on line 26 where you are not checking if q is within the index range.