Cod sursa(job #57146)

Utilizator cezar305Mr. Noname cezar305 Data 1 mai 2007 11:18:28
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.69 kb
VAR T,CT:Array[0..16,0..16]of longint;
    i,j,m,n,nflip,k,ck,s:longint;
begin
  assign(input,'flip.in');reset(input);
  assign(output,'flip.out');rewrite(output);
  readln(n,m);T[0,0]:=0;
  nflip:=1 shl m-1;
  for i:=1 to n do begin
    for j:=1 to m do begin read(t[i,j]);inc(t[i,0],t[i,j]);end;
    readln;
  end;
  for k:=0 to nflip do begin
    ck:=k;CT:=T;
    for j:=m downto 1 do begin
      if ck mod 2=1 then begin
        for i:=1 to n do dec(ct[i,0],2*ct[i,j]);
      end;
      ck:=ck div 2;
    end;
    s:=0; for i:=1 to n do inc(s,abs(ct[i,0]));
    if s>T[0,0] then begin t[0,0]:=s;t[0,1]:=k;end;
  end;
  write(T[0,0],' ',T[0,1]);
  close(input); close(output);
end.