记录编号 |
39468 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
平衡奶牛 |
最终得分 |
100 |
用户昵称 |
wo shi 刘畅 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.613 s |
提交时间 |
2012-07-11 19:18:01 |
内存使用 |
69.59 MiB |
显示代码纯文本
const
hash=17173;
base=1717173;
var
i,j,x,n,total,k,ans:longint;
now:int64;
s,b:array[0..100000,0..30]of longint;
first:array[-2000000..2000000]of longint;
point,next:array[0..4000000]of longint;
function ok(l,r:longint):boolean;
var
i:longint;
begin
for i:=2 to k do
if b[l,i]<>b[r,i] then exit(false);
exit(true);
end;
procedure insert(now,r:longint);
var
i,j:longint;
begin
i:=first[now];
while i<>-maxlongint do
begin
j:=point[i];
if ok(j,r) then
begin
if r-j>ans then ans:=r-j;
exit;
end;
i:=next[i];
end;
inc(total);
point[total]:=r;
next[total]:=first[now];
first[now]:=total;
end;
begin
assign(input,'balline.in'); reset(input);
assign(output,'balline.out'); rewrite(output);
readln(n,k);
for i:=1 to n do
begin
read(x);
for j:=1 to k do
s[i,j]:=s[i-1,j]+((x >> (j-1)) and 1);
end;
for i:=1 to n do
for j:=2 to k do
b[i,j]:=s[i,j]-s[i,j-1];
for i:=-1717173 to 1717173 do
begin
first[i]:=-maxlongint;
point[i]:=-maxlongint;
end;
for i:=0 to n do
begin
now:=0;
for j:=2 to k do
now:=(now*hash+b[i,j]) mod base;
insert(now,i);
end;
writeln(ans);
close(input);
close(output);
end.