Help me i got Runtime error

General topic about Valladolid Online Judge

Moderator: Board moderators

Post Reply
Amir Faisal
New poster
Posts: 4
Joined: Wed Aug 13, 2003 2:47 pm
Location: Bangladesh

Help me i got Runtime error

Post by Amir Faisal »

//runtime error when increse arry size get Time limit
#include<stdio.h>

#define MAXSIZE 20
#define INF -1


char maze[MAXSIZE][MAXSIZE][MAXSIZE];
int cost[MAXSIZE][MAXSIZE][MAXSIZE];
int queue[MAXSIZE*MAXSIZE*MAXSIZE + 1];
int head = 0,tail = 0;
int L,R,C;
int dl[] = {-1,1,0,0,0,0};
int dr[] = {0,0,-1,1,0,0};
int dc[] = {0,0,0,0,-1,1};

void enqueue(int l,int r,int c);
void dequeue(int &l,int &r,int &c);
void solve(void);


void main()
{
int l,r,c;

while((scanf("%d%d%d",&L,&R,&C))&&(L||R||C))
{
for(l=0;l<L;l++)
for(r=0;r<R;r++)
for(c=0;c<C;c++)
maze[l][r][c] = '\0';


for(l=0;l<L;l++)
for(r=0;r<R;r++)
scanf("%s", maze[l][r]);



solve();

}
}

void solve(void)
{
int l,r,c,nl,nr,nc;
int i,j,k,m,n,o,p;
int time = 0;

head=0,tail=0;

for(i=0;i<L;i++)
for(j=0;j<R;j++)
for(k=0;k<C;k++)
cost[j][k] = INF;

for(i=0;i<L;i++)
for(j=0;j<R;j++)
for(k=0;k<C;k++)
{

if(maze[j][k]=='S')
{
enqueue(i,j,k);
cost[j][k] =0;

while(head != tail)
{
dequeue(l,r,c);


for(m=0; m<6; m++)
{
nl = l + dl[m];
nr = r + dr[m];
nc = c + dc[m];

if(maze[nl][nr][nc]=='E')
{
n = nl;
o = nr;
p = nc;

}

if(cost[nl][nr][nc]==INF&&(maze[nl][nr][nc]=='.'||maze[nl][nr][nc]=='E')&&nl<L&&nl>=0&&nr<R&&nr>=0
&&nc<C&&nc>=0)
{
enqueue(nl,nr,nc);
cost[nl][nr][nc] =cost[l][r][c] + 1;
time++;
}
}

}

}

}
if(cost[n][o][p]!=INF&&maze[n][o][p]=='E')
printf("Escaped in %d minute(s).\n", cost[n][o][p]);
else
printf("Trapped!\n");

}

void enqueue(int l,int r,int c)
{
queue[head++] = (l*MAXSIZE + r)*MAXSIZE + c;
}

void dequeue(int &l,int &r,int &c)
{
c = queue[tail]%MAXSIZE;
l = (queue[tail]/MAXSIZE)/MAXSIZE;
r = (queue[tail]/MAXSIZE)%MAXSIZE;
tail++;
}

[cpp][/cpp]
I love my mother.
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

Just suggestion :
Post the number of problem and the problem title
on the topic. This way your chance to get some reply
is slightly higher ... :wink: :wink:
Post Reply

Return to “General”