Cod sursa(job #4983)

Utilizator bogdan315Popescu Bogdan-Ionut bogdan315 Data 9 ianuarie 2007 09:17:01
Problema Jocul Flip Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.03 kb
var a:array[1..16,1..16]of longint;
    n,m,i,j:byte;
    s:longint;
    f,g:text;
procedure linie(i:integer);
var s1:longint;
    l:integer;
begin
s1:=0;
for l:=1 to m do
    begin
    s1:=s1+a[i,l];
    end;
if s1<0 then
   begin
   for l:=1 to m do
       begin
       a[i,l]:=0-a[i,l];
       end;
   end;
end;
procedure coloana(j:integer);
var s1:longint;
    l:integer;
begin
s1:=0;
for l:=1 to n do
    begin
    s1:=s1+a[l,j];
    end;
if s1<0 then
   begin
   for l:=1 to n do
       begin
       a[l,j]:=0-a[l,j];
       end;
   end;
end;
begin
assign(f,'flip.in');reset(f);
assign(g,'flip.out');rewrite(g);
readln(f,n,m);
for i:=1 to n do
    begin
    for j:=1 to m do
        begin
        read(f,a[i,j]);
        end;
    readln(f);
    end;
s:=0;
for i:=1 to n do
    begin
    linie(i);
    end;
for j:=1 to m do
    begin
    coloana(j);
    end;
for i:=1 to n do
    for j:=1 to m do
        begin
        s:=s+a[i,j];
        end;
write(g,s);
close(f);close(G);
end.