Cod sursa(job #19543)

Utilizator raduzerRadu Zernoveanu raduzer Data 19 februarie 2007 18:59:17
Problema Zone Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 3.97 kb
var a:array[0..1000,0..1000]of longint;
    b:array[1..50]of longint;
    n,i,j,l,k,l1,l2,c1,c2,s,q:longint;



procedure ex;
begin
     if (l1>0)and(l2>0)and(c1>0)and(c2>0) then exit;


     q:=0;
     for i:=1 to n do
     begin
          for j:=1 to 9 do
          begin
               for l:=1 to 9 do
               begin
                    if l<>j then
                    for k:=1 to 9 do
                    begin
                         if (k<>l)and(k<>j) then
                         begin
                              if (b[j]+b[l]+b[k]=a[i][0]) then
                              begin
                                   l1:=i;
                                   q:=1;
                                   break;
                              end;
                         end;
                    end;
                    if q=1 then break;
               end;
               if q=1 then break;
          end;
          if q=1 then break;
     end;

     q:=0;
     for j:=1 to n do
     begin
          for i:=1 to 9 do
          begin
               for l:=1 to 9 do
               begin
                    if l<>i then
                    for k:=1 to 9 do
                    begin
                         if (k<>l)and(k<>i) then
                         begin
                              if (b[i]+b[l]+b[k]=a[0][j]) then
                              begin
                                   c1:=j;
                                   q:=1;
                                   break;
                              end;
                         end;
                    end;
                    if q=1 then break;
               end;
               if q=1 then break;
          end;
          if q=1 then break;
     end;

     q:=0;
     for i:=1 to n do
     begin
          for j:=1 to 9 do
          begin
               for l:=1 to 9 do
               begin
                    if l<>j then
                    for k:=1 to 9 do
                    begin
                         if (k<>l)and(k<>j) then
                         begin
                              if a[i][0]=s-(b[j]+b[l]+b[k]) then
                              begin
                                   l2:=i;
                                   q:=1;
                                   break;
                              end;
                         end;
                    end;
                    if q=1 then break;
               end;
               if q=1 then break;
          end;
          if q=1 then break;
     end;

     q:=0;
     for j:=1 to n do
     begin
          for i:=1 to 9 do
          begin
               for l:=1 to 9 do
               begin
                    if l<>i then
                    for k:=1 to 9 do
                    begin
                         if (k<>l)and(k<>i) then
                         begin
                              if a[0][j]=s-(b[i]+b[l]+b[k]) then
                              begin
                                   c2:=j;
                                   q:=1;
                                   break;
                              end;
                         end;
                    end;
                    if q=1 then break;
               end;
               if q=1 then break;
          end;
          if q=1 then break;
     end;

     ex;

end;


begin
     assign(input,'zone.in');
     reset(input);
     assign(output,'zone.out');
     rewrite(output);
     readln(n);
     for i:=1 to 9 do read(b[i]);
     for i:=1 to n do
     begin
          for j:=1 to n do
          begin
               read(a[i][j]);
               s:=s+a[i][j];
          end;
          readln;
          a[i][0]:=s;
     end;
     s:=0;
     for j:=1 to n do
     begin
          for i:=1 to n do
          begin
               s:=s+a[i][j];
          end;
          a[0][j]:=s;
     end;

     ex;

     writeln(l1,' ',l2,' ',c1,' ',c2);
close(output);
end.