issue in Z- Algorithm implementation

Revision en3, by Ahmed_Araby, 2019-06-03 00:02:44

I just learned Z-algorithm (string processing) and in every problem I solve on it when I start the main outer loop of the function from the index 0 I get TLE but when I start from 1 I get Accepted

for example problem 127D - Password

(here I use the algorithm for matching the string with it self to find out max length of sub string that start at any index i and match a prefix of the whole string)

this submission start the loop from 0 and get TLE 54993356 but this submission start from 1 and get Accepted 54993706

and this is the only change that I made for the Accepted solution ( for(int i=1; i<n; i++) // i start form 1 instead of 0 ************************** ) you can see this in the second submission

so some one could give me a reason and tell my why this happen ? thanks in advance

Tags z-algorithm, string problem, string algorithms, implementation

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Ahmed_Araby 2019-06-03 00:02:44 6
en2 English Ahmed_Araby 2019-06-03 00:01:40 169
en1 English Ahmed_Araby 2019-06-02 23:55:34 717 Initial revision (published)