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 1221. Malevich Strikes Back!

why time limit 1 test
Posted by famas 27 Apr 2005 00:56
program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
   var
   zzz:array[1..100,1..100,1..100] of byte;
   a:array[1..100,1..100] of byte;
   i,j,n,otv:integer;
procedure profi(x:integer);
   var
     i1,j1,i2,j2:integer;
     qy:boolean;
begin
   i1:=1;
   repeat
   j1:=1;
   repeat
     qy:=true;
     for i2:=i1 to n do
     for j2:=j1 to n do
     if a[i2,j2]<>zzz[x,i2-i1+1,j2-j1+1] then qy:=false;
     inc(j1);
   until (j1+x>n) or qy;
   inc(i1);
   until  (i1+x>n) or qy;
   if qy then otv:=x;
end;
begin
   for n:=3 to 100 do
   if n mod 3 = 0 then
   begin
   for i:=1 to n div 2 do
   for j:=1 to n div 2-i+1 do
   begin
    zzz[n,i,j]:=1;
    zzz[n,i,n-j+1]:=1;
    zzz[n,n-i+1,j]:=1;
    zzz[n,n-i+1,n-j+1]:=1;
   end;
   end;
   repeat
     fillchar(a,sizeof(a),0);
     readln(n);
     if n>2 then
     begin
     for i:=1 to n do
     begin
     otv:=0;
     for j:=1 to n do
     read(a[i,j]);
     readln;
     end;
     for i:=n downto 3 do
      if (i mod 2 =1) and (otv=0) then profi(i);
     if otv=0 then writeln('No solution')
     else writeln(otv);
     end
     else
     if n<>0 then writeln('No solution');
   until n=0;
end.
end.