Nu aveti permisiuni pentru a descarca fisierul grader_test11.ok
Cod sursa(job #921036)
Utilizator | Data | 20 martie 2013 18:50:48 | |
---|---|---|---|
Problema | Jocul Flip | Scor | 10 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 1.27 kb |
var a:array[0..200,0..200] of longint;
bit:array[0..20] of integer;
fi, fo:text;
i, j, m, n:integer;
aux, poz, s, s1, k, smax, s2:longint;
begin
assign(fi, 'flip.in');
reset(fi);
assign(fo, 'flip.out');
rewrite(fo);
read(fi, n,m);
for j:=1 to n do
for i:=1 to m do
read(fi, a[i,j]);
smax:=0; s2:=0;
for i:=1 to (1 shl m)-1 do begin
aux:=i; poz:=1;
while aux>0 do begin
if aux mod 2=0 then bit[poz]:=1
else bit[poz]:=0;
aux:=aux shr 1;
poz:=poz+1;
end;
s:=0;
for k:=1 to n do begin
s1:=0;
for j:=1 to m do
if bit[j]=1 then s1:=s1+a[k,j]
else s1:=s1-a[k,j];
if (s1<0) then s:=s-s1
else s:=s+s1;
end;
if s>smax then smax:=s;
end;
for k:=1 to m do begin
s1:=0;
for j:=1 to n do
if bit[j]=1 then s1:=s1+a[j,k]
else s1:=s1-a[j,k];
if (s1<0) then s2:=s2-s1
else s2:=s2+s1;
end;
if smax>s2 then s2:=smax;
writeln(fo,s2);
close(fi);
close(fo);
end.