Cele mai bune solutii pentru problema "Imagine"
(ziua1, problema1)


Punctaj Maxim : 35 puncte

Solutii :
Andras Csaba - Bihor - Lic. Ady Endre -35puncte
Marina Constantin    - 27 puncte;
Nechita Onu - Olt    - 27 puncte;
Patrascu Mihai - Dolj - 27 puncte;
Getu Florin         - 27 puncte;
Pandia Lia          - 27 puncte
Comisia Centrala
Fisierele de teste


Program realizat de elevul Andras Csaba - Lic. Ady Endre din Oradea  -
                                        - rezultat final : premiu II - 105 puncte

program primul;
uses crt;
const fajlbe='poza.in';
      fajlki='poza.out';
      max=1000;
var tf:text;
    n,oldal:longint;
    szam:array[1..max] of integer;
    szamdb:integer;
    hiba:integer;

procedure kezdoertek;
begin
  assign(tf,fajlbe);
  reset(tf);
  szamdb:=0;
  while not seekeof(tf) do
   begin
     while not seekeoln(tf) do
      begin
        szamdb:=szamdb+1;
        read(tf,szam[szamdb]);
      end;
     readln(tf);
   end;
  close(tf);
  assign(tf,fajlki);
end;

procedure hibaellenoriz;
var q:integer;
    gyok:real;
begin
  q:=1;
  hiba:=0;
  while (q<=szamdb) and (hiba=0) do
   begin
     if szam[q]=-1 then
                     begin
                       if q+2>szamdb then
                                       begin
                                         if szam[q+1]=0 then hiba:=1
                                                        else hiba:=2;
                                       end;
                       if not ((szam[q+1]=1) or (szam[q+1]=0)) then hiba:=6;
                       if hiba=0 then
                       if szam[q+2]<2 then
                                        begin
                                          if (szam[q+1]=1) or (szam[q+1]=0) then
                                          if szam[q+1]=0 then hiba:=1 else hiba:=2;

                                        end
                                      else n:=n+szam[q+2];
                       q:=q+3;
                     end
                   else
                     begin
                       if not ((szam[q]=1) or (szam[q]=0)) then hiba:=6
                                                           else n:=n+1;
                       if hiba=0 then if (szam[q]=szam[q+1]) and (q+1<=szamdb)                                              then                                                                                             begin
                                                 if szam[q]=1 then hiba:=4 else hiba:=3;
                                               end;
                       if hiba=0 then
                        if (szam[q+1]=-1) and (szam[q+2]=szam[q]) then
                                             begin
                                               if szam[q]=1 then hiba:=4
                                                            else hiba:=3;
                                             end;
                       q:=q+1;
    end;
  end;
if hiba=0 then
            begin
              gyok:=sqrt(n);
              if round(gyok)<>gyok then hiba:=5 else oldal:=round(gyok);
            end;
end;

procedure kiir;
var q:integer;
    oldaltart:integer;
procedure kiir(mit:byte;hanyszor:integer);
var q:integer;
begin
  for q:=1 to hanyszor do
                        begin
                          if oldaltart>=oldal then
                                                begin
                                                  writeln(tf);
                                                  oldaltart:=0;
                                                end;
                          write(tf,mit);
                          oldaltart:=oldaltart+1;
                        end;

end;

begin
  rewrite(tf);
  writeln(tf,oldal);
  q:=1;
  oldaltart:=0;
  while q<=szamdb do
                   begin
                     if szam[q]=-1 then
                                     begin
                                       kiir(szam[q+1],szam[q+2]);
                                       q:=q+3;
                                     end
                                   else
                                     begin
                                       kiir(szam[q],1);
                                       q:=q+1;
                                     end;
                   end;
  close(tf);
end;

begin
  kezdoertek;
  hibaellenoriz;
  if hiba<>0 then
               begin
                 rewrite(tf);
                 writeln(tf,'NU');
                 writeln(tf,hiba);
                 close(tf);
               end
             else kiir;
end.

[BACK]


Program realizat de Comisia Centrala a Olimpiadei Nationale de Informatica

{program comisie - tratarea erorilor incompleta- Prof. Ioana Tantas
                                               - Prof. Rodica Pintea }
program p1;

var n,m,i,j,k,len:longint;
    f:text;
    nume:string;
    a:array[1..1000]of integer;
procedure error(i:byte);
begin
  rewrite(f);
  writeln(f,'NU');
  writeln(f,i);
  close(f);
  halt
end;

begin
  {Citeste datele de intrare}
  assign(f,'poza.in');
  reset(f);
  m:=0;
  while not seekeof(f) do
   begin
     m:=m+1;
     read(f,a[m]);
   end;
  close(f);
  n:=0;
  i:=1;
  while i<=m do
   if a[i]=-1 then begin
                     n:=n+a[i+2];i:=i+3
                   end
              else begin
                     n:=n+1;i:=i+1
                   end;
 len:=round(sqrt(n));
 assign(f,'poza.out');
 if sqr(len)<>n then error(5);
 rewrite(f);
 {Scrie dimensiunea matricii}
 writeln(f,len);
 i:=1;k:=0;
 while i<=m do begin
                 if a[i]=-1 then
                    begin
                      if not(a[i+1] in [0,1]) then error(6);
                      if a[i+2]<=1 then error(a[i+1]);
                      for j:=1 to a[i+2] do begin
                                              inc(k);
                                              write(f,a[i+1]);
                                              if k=len then
                                                         begin
                                                           writeln(f);k:=0
                                                         end;
                                            end;
                      i:=i+3
                    end
                             else if not(a[i] in [0,1]) then error(5)
                                                        else begin
                                                               write(f,a[i]);
                                                               i:=i+1;k:=k+1;
                                                               if k=len then
                                                                          begin
                                                                            writeln(f);
                                                                            k:=0
                                                                          end
                                                             end;
               end;
  close(f);
end.

[BACK]


 


Fisierele de teste :

Test 1 :
1 2 3 4 5
1 1 1 1 1
N

Test 2 :
2 3 1 4 5
0 1 0 1 1
A

Test 3 :
4 3 1 2 5
0 1 1 1 0
x

Test 4 :
5 1 2 4 3
0 1 0 0 1
k

Test 5 :
2 3 1 4 5
1 1 0 0 0
U

Test 6 :
2 1 3 5 4
0 0 1 1 1
e

Test 7 :
1 2 3 4 5
1 0 1 0 1
J

Test 8 :
4 1 3 2 5
0 0 1 0 0
r

Test 9 :
3 1 2 4 5
1 0 0 0 1
d

Test 10 :
3 2 4 1 5
1 0 0 0 0
fr

Test 11 :
3 4 1 5 2
0 0 1 0 1
Ger

Test 12 :
1 4 5 2 3
0 1 0 1 0
AZieZiDesarbatoareBihoreana

Test 13 :
1 2 3 4 5
1 1 0 1 1
abcdUTstxvwuCDEFGHgfedABghijklmnopJZsrqpKLMNOPQRdefgZJpqrsTUabcdUTstxvwuCDEFGHgfedABghijklmnop
JZsrqpKLMNOPQRdefgZJpqrsTU

Test 14 :
1 2 3 4 5
1 1 0 1 1
OlimpiadaNationalaDeJnformaticaDeLaOradeaAduceMultePremiiElevilorPunctBBBAAAFFFTTTAAAOlimpiada
NationalaDeJnformaticaDeLaOradeaAduceMultePremiiElevilorPunctBBBAAAFFFTTTAAAOlimpiadaNationala
DeJnformaticaDeLaOradeaAduceMultePremiiElevilorPunctBBBAAAFFFTTTAAAOlimpiadaNationalaDeJnforma
ticaDeLaOradeaAduceMultePremiiElevilorPunctBBBAAAFFFTTTAAAOlimpiadaNationalaDeJnformaticaDeLaO
radeaAduceMultePremiiElevilorPunctBBBAAAFFFTTTAAAOlimpiadaNationalaDeJnformaticaDeLaOradeaAduc
eMultePremiiElevilorPunctPaPa

[BACK]