bzoj 3916 暴力+hash

61 篇文章 0 订阅
2 篇文章 0 订阅

题意:将原串复制一遍再随机插入一个字符,给出操作后的字符串求原串

...暴力枚举插入的是哪个,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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值