← Back to topics
Topic

RBgrid

g
gigac
Can someone tell me what's wrong with me code. It gives me Exit Code not zero :?
h
halil
First, input. Should be:

readln(n,m);
for i:= 1 to n do begin
for j:= 1 to m do read(L[i,j]);
readln;
end;...

...
Second, what with
(L[A,B]='B')

A
Al3kSaNdaR
And you should go from 2 to n -1 and 2 to m - 1.
g
gigac
But 1 <= n, m <= 1 000 :?
halil...I have function TF
inside the function the first if is L[A,B] :) :)

Edit:
The last test is wrong result, Can someone tell me where I'm wrong...
h
halil
Sorry, I didn't see. I think that variable C should bee longint, not integer. And it will be OK.
Some notice:

- No need If TF(I,J) = True Then ... , enough is If TF(I,J) Then ...

- Becouse 2 <= i <= N-1 and 2 <= j <= M-1, I think that could be:

Function TF(a,b : Integer) : Boolean;
Begin
TF:= (L[A,B]='B') and (L[A-1,B]='B') And (L[A+1,B]='B') And (L[A,B-1]='B') And (L[A,B+1]='B');
End;

so, do you realy need function TF? (increase spped).
g
gigac
I change the variable from Integer to LongInt.

About the function..
What if a=1 and b=1..when I try A-1 it will show an error.
Can I define the array from 0..1000 ?
h
halil
No need. I used 'array[1..1000,1..1000] Of Char'.
If a=1, no matter. You use
for i:= 2 to n-1 do
for j:= 2 to m-1 do
...
g
gigac
Ahaaam...
I understand :)
Thanks ma friend :)
m
matteo123
use

for(i=2;i<=n-1;i++)
{
for(j=2;j<=m-1;j++)
{



as halil said
d
dancsi
nope...with those only one test case is working...I index the elements from 0
D
Daniel93
make your matrix a little bigger
m
matteo123
n i m (1 <= n, m <= 1 000).
his matrix is ok.
I think something else is the problem
d
dancsi
THANKS! now the dimensions are 1443*1443 and it works (these are the maximum dimensions)