Please subscribe to the official Codeforces channel in Telegram via the link: ×

eigenvalue's blog

By eigenvalue, history, 14 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: Solution:

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

13 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.