比赛 |
20120711 |
评测结果 |
AAAAAATTATTT |
题目名称 |
平衡奶牛 |
最终得分 |
58 |
用户昵称 |
isabella |
运行时间 |
5.012 s |
代码语言 |
Pascal |
内存使用 |
11.61 MiB |
提交时间 |
2012-07-11 11:50:51 |
显示代码纯文本
type arr=array[1..30]of longint;
var
n,k,i,j,t,delt,min,max,ans:longint;
a:array[1..100000]of arr;
tot:arr;
procedure dfs(s,len:longint;b:arr;delt:longint);
var i,min,max:longint;
tt:arr;
begin
if delt=0 then begin ans:=len;exit;end;
if len-delt<=ans then exit;
tt:=b;
min:=maxlongint;max:=0;
for i:=1 to k do
begin
for j:=s to s+delt-1 do b[i]:=b[i]-a[j,i];
if b[i]<min then min:=b[i];
if b[i]>max then max:=b[i];
end;
dfs(s+delt,len-delt,b,max-min);
min:=maxlongint;max:=0;
for i:=1 to k do
begin
for j:=s+len-delt to s+len-1 do tt[i]:=tt[i]-a[j,i];
if tt[i]<min then min:=tt[i];
if tt[i]>max then max:=tt[i];
end;
dfs(s,len-delt,tt,max-min);
end;
begin
assign(input,'balline.in');reset(input);
assign(output,'balline.out');rewrite(output);
{init}
readln(n,k);
for i:=1 to n do
begin
readln(j);
t:=0;
while j<>0 do
begin inc(t);a[i,t]:=j mod 2;
j:=j div 2;
tot[t]:=tot[t]+a[i,t];
end;
end;
{work}
min:=maxlongint;max:=0;
for i:=1 to k do
begin
if tot[i]<min then min:=tot[i];
if tot[i]>max then max:=tot[i];
end;
delt:=max-min;
ans:=0;
dfs(1,n,tot,delt);
writeln(ans);
{for i:=1 to n do
begin for j:=1 to k do write(a[i,j],' ');
writeln;end;}
close(input);close(output);
end.