题意:将原串复制一遍再随机插入一个字符,给出操作后的字符串求原串
...暴力枚举插入的是哪个,hash判断一下即可..
注意:(1)所谓不同串是串本身不同,截的位置不同但截出的串相同是一样的,并不算多种情况
(2)unique打成‘uniuqe’真是脑残起来手贱的自己都害怕....
{$Q-}
var
n,l,t1,tl,tr :longint;
t2,t3 :qword;
i :longint;
base,hash :array[0..2000010] of qword;
s :ansistring;
function get_hash(l,r:longint):qword;
begin
exit(hash[r]-hash[l-1]*base[r-l+1]);
end;
begin
readln(n);
readln(s); t1:=0;
l:=(n-1) div 2;
if (n and 1=0) then
begin
writeln('NOT POSSIBLE');exit;
end;
base[0]:=1; tl:=1; tr:=0;
for i:=1 to n do base[i]:=base[i-1]*137;
for i:=1 to n do hash[i]:=hash[i-1]*137+ord(s[i]);
for i:=1 to n do
begin
if i<=l then
begin
if (i>1) then
t2:=get_hash(1,i-1)*base[l-i+1]+get_hash(i+1,l+1) else t2:=get_hash(2,1+l);
t3:=get_hash(l+2,n);
if t2=t3 then
begin
if get_hash(tl,tr)<>t2 then
begin
inc(t1);
if t1>1 then break;
tl:=l+2; tr:=n;
end;
end;
end else
begin
t2:=get_hash(1,l);
if (i=l+1) then t3:=get_hash(l+2,n) else
if (i<n) then t3:=get_hash(l+1,i-1)*base[n-i]+get_hash(i+1,n)
else t3:=get_hash(l+1,n-1);
if t2=t3 then
begin
if get_hash(tl,tr)<>t2 then
begin
inc(t1);
if t1>1 then break;
tl:=1; tr:=l;
end;
end;
end;
end;
if t1=0 then writeln('NOT POSSIBLE') else
if t1=1 then writeln(copy(s,tl,tr)) else
if t1>1 then writeln('NOT UNIQUE');
end.
——by Eirlys