记录编号 39479 评测结果 AAAAAAAAAAAE
题目名称 平衡奶牛 最终得分 91
用户昵称 Gravatarisabella 是否通过 未通过
代码语言 Pascal 运行时间 0.395 s
提交时间 2012-07-11 21:44:05 内存使用 12.75 MiB
显示代码纯文本
const size=300000;
type
 point=^node;
 node=record
  data:longint;
  next:point;
  end;
var
 a:array[0..100000,1..30]of longint;
 n,k,i,j,t,ans:longint;
 ha:array[1..300000]of point;

function check(x,y:longint):boolean;
 var i:longint;
 begin
  for i:=1 to k do
   if a[x,i]<>a[y,i] then exit(false);
  exit(true);
 end;
function hash(x:longint):longint;
 var temp,i:longint;
     p:int64;
 begin
   temp:=0;p:=1;
   for i:=1 to k do
    begin
     temp:=(temp+p*a[x,i])mod size;
     p:=(p*77)mod size;
    end;
   exit(temp+1);
 end;
procedure pan(x,i:longint);
 var p:point;flag:boolean;
 begin
  flag:=false;
  p:=ha[x];
  while p<>nil do
   begin
    if(check(p^.data,i)) then
     begin
      if (i-p^.data)>ans then ans:=i-p^.data;
      flag:=true;
     end;
    p:=p^.next;
   end;
  if flag=false then
   begin
    new(p);p^.data:=i;p^.next:=ha[x];ha[x]:=p;
   end;
 end;

begin
assign(input,'balline.in');reset(input);
assign(output,'balline.out');rewrite(output);
 readln(n,k);
 for i:=1 to k do a[0,i]:=0;
 for i:=1 to n do
  begin
   readln(t);j:=0;
   a[i]:=a[i-1];
   while t<>0 do
    begin inc(j);a[i,j]:=a[i,j]+(t mod 2);t:=t div 2;end;
  end;

 ans:=0;
 pan(hash(0),0);
 for i:=1 to n do
  begin
   if i=80000 then
    begin
      ans:=ans;
    end;
   for j:=k downto 1 do a[i,j]:=a[i,j]-a[i,1];
   pan(hash(i),i);
  end;
 writeln(ans);
close(input);close(output);
end.