ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1423. String Tale

Time limit test#10
Posted by Plakhov618 16 Dec 2012 23:47
Why?
code pascal
program z1;
var s, s1:string;
    n, x:longint;
begin
  readln(n);
  readln(s);
  readln(s1);
  if s=s1 then write(0)
  else begin
  s:=s+s;
  case pos(s1, s) of
  1..250000:writeln(n-pos(s1, s)+1);
  else write(-1);
  end;
  end;
  readln;
  end.
Re: Time limit test#10
Posted by Noob 17 Dec 2012 02:55
Your algorithm is wrong, read more about KMP algorithm or string hashing

P.S. Test for you:
aaa...aaa
aaa...aab