{ fp } {* * Problem : SUBSTR * Contest : UOI-2006 (Dnepropetrovsk) * Type : Solution * Date : April 1, 2006 * Author : Sergey Savchuk * Language : Pascal * Compiler : Free Pascal * Algorithm: Fast solution (without explicit buffer specification), with optimized returning of the best string (usage of an array) *} Var fi,fo: Text; s: string; ls: byte absolute s; a:array['a'..'z'] of Longint; c:array[0..10000000] of char; na,i,k,max,maxna: longint; ch: char; Begin Assign(fi,'SUBSTR.DAT'); Reset(fi); na:=1; While not Eof(fi) do Begin Readln(fi,s); For i:=1 to ls do Begin inc(k); c[k]:=s[i] End End; For i:=1 to k do Begin if na<=a[c[i]] Then na:=a[c[i]]+1; if i-na+1>max Then Begin Max:=i-na+1; maxna:=na End; a[c[i]]:=i; End; Assign(fo,'SUBSTR.SOL'); ReWrite(fo); For i:=1 to max do Write(fo,c[maxna+i-1]); Writeln(fo); Close(fo) End.