记录编号 |
39469 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
平衡奶牛 |
最终得分 |
100 |
用户昵称 |
zhangchi |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.475 s |
提交时间 |
2012-07-11 19:31:40 |
内存使用 |
92.48 MiB |
显示代码纯文本
type
node=record
postion,next:int64;
end;
var
i,j:longint;
n,temp,k,ans,tot,t,pos:int64;
q:boolean;
a:array[1..100000] of int64;
sum:array[1..30,0..100000] of int64;
hash:array[0..3000008] of int64;
link:array[1..3000000] of node;
begin
assign(input,'balline.in'); reset(input);
assign(output,'balline.out'); rewrite(output);
readln(n,k);
for i:=1 to n do
readln(a[i]);
for i:=1 to k do
for j:=1 to n do
sum[i,j]:=sum[i,j-1]+(a[j] shr (i-1)) and 1;
for i:=1 to k-1 do
for j:=1 to n do
sum[i,j]:=sum[i,j]-sum[i+1,j];
for i:=0 to n do
begin
temp:=1;
for j:=1 to k-1 do
temp:=(temp*13137+sum[j,i]) mod 1000007;
t:=hash[temp];
while t<>0 do
begin
pos:=link[t].postion;
q:=true;
for j:=1 to k-1 do
if sum[j,i]<>sum[j,pos] then
begin q:=false; break; end;
if q=true then
if i-pos>ans then ans:=i-pos;
t:=link[t].next;
end;
inc(tot);
link[tot].next:=hash[temp];
hash[temp]:=tot;
link[tot].postion:=i;
end;
writeln(ans);
close(input); close(output);
end.