ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1501. Sense of Beauty

Why wa 18
Posted by valdem 10 Mar 2007 18:07
there is my code:
program z1501;
Var s,s1,s2:string;
    i,l,n:longint;
    p:shortint;
    st:boolean;
begin
 readln(n);
 readln(s);
 readln(s1);
 s:=s+'   ';
 s1:=s1+'   ';
 s2:=''; i:=1; l:=1;
st:=false;
 while True do begin
 while ((i<=n)or(l<=n))and not st do begin
       if (p=-1)and(s[i]='1')and(s[i+1]='1')and(s[i+2]='0')then begin
          s2:=s2+'11'; inc(i,2); p:=1;
          break;
       end;
       if (p=-1)and(s1[l]='1')and(s1[l+1]='1')and(s1[l+2]='0')then begin
          s2:=s2+'22'; inc(l,2); p:=1;
          break;
       end;
       if (p=1)and(s[i]='0')and(s[i+1]='0')and(s[i+2]='1')then begin
          s2:=s2+'11'; inc(i,2); p:=-1;
          break;
       end;
       if (p=1)and(s1[l]='0')and(s1[l+1]='0')and(s1[l+2]='1')then begin
          s2:=s2+'22'; inc(l,2); p:=-1;
          break;
       end;

       if (p=-1)and(s[i]='1')and(s[i+1]='0')then begin
          s2:=s2+'1'; inc(i); p:=0;
          break;
       end;
       if (p=-1)and(s1[l]='1')and(s1[l+1]='0')then begin
          s2:=s2+'2'; inc(l); p:=0;
          break;
       end;
       if (p=1)and(s[i]='0')and(s[i+1]='1')then begin
          s2:=s2+'1'; inc(i); p:=0;
          break;
       end;
       if (p=1)and(s1[l]='0')and(s1[l+1]='1')then begin
          s2:=s2+'2'; inc(l); p:=0;
          break;
       end;

       if (p=0)and(s[i]='1')and(s[i+1]='0')then begin
          s2:=s2+'1'; inc(i); p:=1;
          break;
       end;
       if (p=0)and(s1[l]='1')and(s1[l+1]='0')then begin
          s2:=s2+'2'; inc(l); p:=1;
          break;
       end;
       if (p=0)and(s[i]='0')and(s[i+1]='1')then begin
          s2:=s2+'1'; inc(i); p:=-1;
          break;
       end;
       if (p=0)and(s1[l]='0')and(s1[l+1]='1')then begin
          s2:=s2+'2'; inc(l); p:=-1;
          break;
       end;

       if (p=-1)and(s[i]='1')then begin
          s2:=s2+'1'; inc(i); p:=0;
          break;
       end;
       if (p=-1)and(s1[l]='1')then begin
          s2:=s2+'2'; inc(l); p:=0;
          break;
       end;
       if (p=1)and(s[i]='0')then begin
          s2:=s2+'1'; inc(i); p:=0;
          break;
       end;
       if (p=1)and(s1[l]='0')then begin
          s2:=s2+'2'; inc(l); p:=0;
          break;
       end;

       if (p=0)and(s[i]='1')then begin
          s2:=s2+'1'; inc(i); p:=1;
          break;
       end;
       if (p=0)and(s1[l]='1')then begin
          s2:=s2+'2'; inc(l); p:=1;
          break;
       end;
       if (p=0)and(s[i]='0')then begin
          s2:=s2+'1'; inc(i); p:=-1;
          break;
       end;
       if (p=0)and(s1[l]='0')then begin
          s2:=s2+'2'; inc(l); p:=-1;
          break;
       end;
       st:=true;
 end;
 if (length(s2)=2*n)or st then
    break;
 end;
 if length(s2)=2*n then
    writeln(s2)
 else
    writeln('Impossible');
end.