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 1033. Labyrinth

why WA
Posted by wangchun 19 Jul 2003 14:32
const move:array[1..4,1..2]of shortint=((1,0),(0,1),(-1,0),(0,-1));
var sz,s:array[1..33,1..33]of byte;
    n:byte;
    total:longint;
procedure init;
var i,j:byte;
    c:char;
begin
     fillchar(sz,sizeof(sz),0);
     readln(n);
     for i:=1 to n do
         begin
              for j:=1 to n do
                  begin
                       read(c);
                       while not (c in['.','#']) do
                             read(c);
                       if c='.' then
                          sz[i,j]:=0
                                else
                          sz[i,j]:=1;
                  end;
              readln;
         end;
end;
procedure find(a,b:byte);
var i,j:byte;
begin
     i:=a-1;
     j:=b;
     if (i in[1..n])and(j in[1..n]) then
        if sz[i,j]=0 then
        if s[i,j]=0 then
           begin
                s[i,j]:=1;
                find(i,j);
           end;
     i:=a+1;
     j:=b;
     if (i in[1..n])and(j in[1..n]) then
        if sz[i,j]=0 then
        if s[i,j]=0 then
           begin
                s[i,j]:=1;
                find(i,j);
           end;
     i:=a;
     j:=b-1;
     if (i in[1..n])and(j in[1..n]) then
        if sz[i,j]=0 then
        if s[i,j]=0 then
           begin
                s[i,j]:=1;
                find(i,j);
           end;
     i:=a;
     j:=b+1;
     if (i in[1..n])and(j in[1..n]) then
        if sz[i,j]=0 then
        if s[i,j]=0 then
           begin
                s[i,j]:=1;
                find(i,j);
           end;
end;
procedure make;
var i,j,t,a,b:byte;
begin
     total:=0;
     fillchar(s,sizeof(s),0);
     find(1,1);
     if sz[1,1]<>0 then
        inc(total,2);
     find(n,n);
     if sz[n,n]<>0 then
        inc(total,2);
     for i:=1 to n do
         for j:=1 to n do
             if s[i,j]<>0 then
                begin
                     if i in[1,n] then
                        inc(total);
                     if j in [1,n] then
                        inc(total);
                     if ((i=1)and(j=1))or((i=n)and(j=n)) then
                        dec(total,2);
                     for t:=1 to 4 do
                         begin
                         a:=i+move[t,1];
                         b:=j+move[t,2];
                         if (a in[1..n])and(b in[1..n]) then
                            begin
                                 if not((a=1)and(b=1)or(a=n)and(b=n))
then
                                    if sz[a,b]<>0 then
                                       inc(total);
                            end;
                         end;
                end;
     total:=total*9;
end;
procedure print;
begin
     writeln(total);
end;
begin
     init;
     make;
     print;
end.