Cod sursa(job #270482)

Utilizator andreirulzzzUPB-Hulea-Ionescu-Roman andreirulzzz Data 4 martie 2009 01:57:20
Problema Jocul Flip Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.67 kb
var a,b:array[0..20,0..16] of longint;
    f:text;
    i,smax,scom,j,s,m,n:integer;
{-------------------------}
procedure suma;
begin
     assign(f,'flip.in');
     reset(f);
     readln(f,n,m);
     for i:=1 to n do
         for j:=1 to m do begin
             read(f,a[i,j]);
             a[0,j]:=a[0,j]+a[i,j];
             a[i,0]:=a[i,0]+a[i,j];
             scom:=scom+a[i,j];
             end;
close(f);
end;
{-------------------------}
procedure flipcol;
var j,k:byte;
begin
     for j:=1 to m do
         if b[0,j]<0 then
         for k:=1 to n do begin
         b[i,k]:=b[i,k]*(-1);
         b[i,0]:=b[i,0]+2*b[k,i];
         s:=s+2*b[i,j];
         b[0,k]:=b[0,k]+2*b[k,i];
     end;
end;
{-------------------------}
procedure fliplin;
var k,j:byte;
begin
     for j:=1 to n do
         if b[j,0]<0 then
            for k:=1 to m do begin
         b[j,k]:=b[j,k]*(-1);
         b[0,k]:=b[0,k]+2*b[j,k];
         s:=s+2*b[j,k];
         b[j,0]:=b[j,0]+2*b[j,k];
         end;
end;
{-------------------------}
begin
scom:=0;
suma;
for i:=1 to m do begin
    b:=a; s:=scom;
    for j:=1 to n do begin
        b[j,i]:=b[j,i]*(-1);
        b[j,0]:=b[j,0]+2*b[j,i];
        s:=s+2*b[j,i];
        b[0,i]:=b[0,i]+2*b[j,i];
        end;
    fliplin;
    flipcol;
    if s>smax then smax:=s;
    end;
{for i:=1 to n do begin
    b:=a; s:=scom;
    for j:=1 to m do begin
        b[i,j]:=b[i,j]*(-1);
        b[j,0]:=b[j,0]+2*b[j,i];
        s:=s+2*a[j,i];
        b[0,i]:=b[0,i]+2*b[j,i];
        end;
    flipcol;
    fliplin;
    if s>smax then smax:=s;
    end;    }
assign(f,'flip.out');
rewrite(f);
write(f,smax);
close(f);
end.