(* Gli orologi (IOI 1994) Copyright (C) 2000 Paolo Boldi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) program Ioi9421; {$R+} uses Dos; const infl: array [1..9,1..9] of byte= ((1,1,0,1,0,0,0,0,0), (1,1,1,0,1,0,0,0,0), (0,1,1,0,0,1,0,0,0), (1,0,0,1,1,0,1,0,0), (1,0,1,0,1,0,1,0,1), (0,0,1,0,1,1,0,0,1), (0,0,0,1,0,0,1,1,0), (0,0,0,0,1,0,1,1,1), (0,0,0,0,0,1,0,1,1)); (* infl[j,i] dice se la mossa i influisce sull'orologio j *) nomefin='input.txt'; nomefout='output.txt'; var a: array [1..9] of word; (* a[i]=# mosse di tipo i *) si: array [1..9] of word; (* si[j]=stato iniziale orologio j *) function ok: boolean; (* Restituisce true se si Š una soluzione corretta *) var i,j: byte; giusto: boolean; v: word; begin giusto:=true; for j:=1 to 9 do begin v:=si[j]; for i:=1 to 9 do v:=v+infl[j,i]*a[i]; giusto:=(v mod 4=0); if (not giusto) then break end; ok:=giusto end; procedure inp; (* Lettura input *) var f: text; j: byte; begin assign(f,nomefin); reset(f); for j:=1 to 9 do read(f,si[j]); close(f) end; function min(a,b: byte): byte; begin if (a3) then continue; if (ok) then goto soluzione; end; soluzione: assign(f,nomefout); rewrite(f); for i:=1 to 9 do for c:=1 to a[i] do write(f,i); writeln(f); close(f) end.