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 1684. Jack's Last Word

WA 1!!! HEEEEEEEELP!!!
Posted by Felix_Mate 13 Jul 2015 18:59
I can't find any error. My program solve all tests,my I got WA1!!!
My code:
 var
 Z:array[1..151000] of longint;
 A,C:array[1..151000] of char;
 N,L,R,i,j,k,ind,M,t:longint;
 ch:char;
 find:boolean;


function Min(x,y:longint):longint;
begin
 if(x>y) then x:=y;
 Min:=x;
end;

BEGIN
 N:=0;

 ch:='a';
 while(ord(ch)>50) do begin
  read(ch);
  if(ord(ch)>50) then begin
   inc(N);
   A[N]:=ch;
  end;
 end;

 A[N+1]:='+';
 ind:=N+1;
 inc(N);
 readln;

 ch:='a';
 while(ord(ch)>50) do begin
  read(ch);
  if(ord(ch)>50) then begin
   inc(N);
   A[N]:=ch;
  end;
 end;


 Z[1]:=N;
 R:=0;
 L:=0;

 for i:=2 to N do begin
  if(i<=r) then Z[i]:=min(R-i+1,Z[i-L+1])
  else Z[i]:=0;
  while(i+z[i]<=N)and(A[i+z[i]]=A[z[i]+1]) do inc(z[i]);
  if(i+z[i]-1>r) then begin
   L:=i;
   R:=i+z[i]-1;
  end;
 end;


 find:=true;
 i:=N;
 while(i>=ind+1) do begin
  k:=i;
  while(i>=ind+1)and(Z[i]<k-i+1) do dec(i);
  if(i<ind+1) then find:=false;
  dec(i);
 end;

 if(find) then begin
   writeln('No ');
   i:=N;
   M:=1;
   while(i>=ind+1) do begin
    k:=i;
    while(i>=ind+1)and(Z[i]<k-i+1) do dec(i);
    t:=M;
    for j:=k downto i do begin
     C[t]:=A[j];
     inc(t);
    end;
    C[t+1]:=' ';
    M:=t+2;
    dec(i);
   end;

   for i:=M-2 downto 1 do begin
    write(C[i]);
   end;
 end
 else begin
  write('Yes');
 end;
END.