记录编号 |
39458 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
平衡奶牛 |
最终得分 |
100 |
用户昵称 |
czp |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.725 s |
提交时间 |
2012-07-11 17:47:59 |
内存使用 |
23.81 MiB |
显示代码纯文本
type aaa=array[0..30] of longint;
var
op:array[0..100000] of aaa;
sum:array[0..30,0..100000] of longint;
p:array[1..33] of longint;
i,j,m,n,k,tt,min,max,ans:longint;
mid,tp:aaa;
function pan1(xx,yy:aaa):boolean;
var i:longint;
begin
pan1:=false;
for i:=1 to k-1 do
begin
if xx[i]<yy[i] then begin pan1:=true; ;break; end;
if xx[i]>yy[i] then begin pan1:=false; ;break; end;
end;
end;
function pan2(xx,yy:aaa):boolean;
var i:longint;
begin
pan2:=false;
for i:=1 to k-1 do
begin
if xx[i]>yy[i] then begin pan2:=true;break; end;
if xx[i]<yy[i] then begin pan2:=false;break; end;
end;
end;
function ok(xx,yy:aaa):boolean;
var i:longint;
begin
ok:=true;
for i:=1 to k-1 do
if xx[i]<>yy[i] then
begin ok:=false;break; end;
end;
procedure sort(l,r:longint);
var i,j:longint;
begin
i:=l;
j:=r;
mid:=op[(l+r) div 2];
repeat
while pan1(op[i],mid) do inc(i);
while pan2(op[j],mid) do dec(j);
if i<=j then
begin
tp:=op[i];
op[i]:=op[j];
op[j]:=tp;
inc(i);
dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
begin
assign(input,'balline.in');reset(input);
assign(output,'balline.out');rewrite(output);
readln(n,k);
p[1]:=1;
for i:=2 to k do p[i]:=p[i-1]*2;
for i:=1 to n do
begin
readln(m);
for j:=1 to k do
begin
sum[j,i]:=sum[j,i-1];
if m and p[j]=p[j] then inc(sum[j,i]);
end;
end;
tt:=n+1;
for i:=1 to n do
begin
op[i,0]:=i;
for j:=1 to k-1 do
op[i,j]:=sum[j+1,i]-sum[j,i];
end;
sort(1,tt);
min:=op[1][0];
max:=op[1][0];
for i:=2 to tt do
begin
if ok(op[i-1],op[i]) then
begin
if op[i][0]<min then min:=op[i][0];
if op[i][0]>max then max:=op[i][0];
if max-min>ans then ans:=max-min;
end else
begin
min:=op[i][0];
max:=op[i][0];
end;
end;
writeln(ans);
close(input);close(output);
end.