oops ........
if you read input with "scanf" , then it use 3 secs to read ,
so those who got tle shoud find a fast input way ...
Moderator: Board moderators
mogers wrote:SRX wrote:oops ........
if you read input with "scanf" , then it use 3 secs to read ,
so those who got tle shoud find a fast input way ...
by the way, you could tell us how![]()
char buf[BUF_SIZE];
char *c;
for (i = 0; i < row; ++i) {
fgets(buf, sizeof(buf), stdin);
c = buf;
for (j = 0; j < col; ++j) {
while (*c == ' ') ++c;
maze[i][j] = *c++ - '0';
}
}
I use 10 non STL queues but I'm not sure about their MAX Size (i guess that my problem is the size of the array - defined as 999)
How do you implement Queues ? I use an array. I think that a linked list saves memory but is slower.

for (i=0;i<rows;i++) {
for (j=0;j<cols;j++)
{
maze[i][j] = getchar();
maze[i][j] -= '0';
getchar(); /* read ' ' or '\n' */
}
}In this way, you don't need to queue distance information.
It is much faster than using the heap (using heap(not STL) took 3 ~ 4 secs).
#include<stdio.h>
int maze[1000][1000],cum[1000][1000];
int main()
{
int i,j,test,m,n;
scanf("%d",&test);
++test;
while(--test)
{
scanf("%d%d",&m,&n);
for(i=0;i<m;++i)
for(j=0;j<n;scanf("%d",&maze[i][j]),++j);
cum[0][0]=maze[0][0];
for(i=1;i<n;cum[0][i]=cum[0][i-1]+maze[0][i],++i);
for(i=1;i<m;cum[i][0]=cum[i-1][0]+maze[i][0],++i);
for(i=1;i<m;++i)
for(j=1;j<n;++j)
cum[i][j]=(cum[i-1][j]<cum[i][j-1]?cum[i-1][j]:cum[i][j-1])+maze[i][j];
printf("%d\n",cum[m-1][n-1]);
}
return 0;
}
1
4
5
0 9 9 9 9
0 9 0 0 0
0 0 0 9 0
9 9 9 9 0

Users browsing this forum: No registered users and 1 guest