Why WA?
Послано
GeGe 30 мар 2003 20:37
I have WA. Why?
const MaxN = 33;
OneSqure = 9;
type TArr = array[0 .. MaxN + 1, 0 .. MaxN + 1] of Byte;
var A : TArr;
C : array[0 .. MaxN + 1, 0 .. MaxN + 1] of Boolean;
N, Count : Integer;
procedure Init;
var ch : Char;
i, j : Byte;
begin
Read(N);
fillchar(A, SizeOf(A), 0);
for i := 0 to N + 1 do
begin
A[i, 0] := 1;
A[0, i] := 1;
A[i, N + 1] := 1;
A[N + 1, i] := 1;
end;
A[N + 1, N] := 0;
A[N, N + 1] := 0;
A[1, 0] := 0;
A[0, 1] := 0;
for i := 1 to N do
for j := 1 to N do
begin
Read(ch);
while Not(ch in ['.', '#']) and Not(EOF) do Read(ch);
if ch = '#' then A[i, j] := 1;
end;
end;
procedure Rec(const pi, pj : Byte);
begin
if (A[pi, pj] = 1) or C[pi, pj] or
(pi < 1) or (pj < 1) or (pi > N) or (pj > N) then exit;
C[pi, pj] := true;
Rec(pi + 1, pj);
Rec(pi, pj + 1);
Rec(pi - 1, pj);
Rec(pi, pj - 1);
end;
procedure Solve;
var i, j : Integer;
begin
Rec(1, 1);
Count := 0;
for i := 1 to N do
for j := 1 to N do
if C[i, j] then
begin
if A[i, j - 1] = 1 then Inc(Count);
if A[i - 1, j] = 1 then Inc(Count);
if A[i, j + 1] = 1 then Inc(Count);
if A[i + 1, j] = 1 then Inc(Count);
end;
end;
begin
Init;
Solve;
WriteLn(Count*OneSqure);
end.