Page 3 of 4

### 10500 WA !!!! HELP

Posted: Fri Jul 08, 2005 9:21 am
Hi all,
I'm getting lots of WA for this easy problem. Plz help me to find out my error. Here is my code. Thanx in advance.

Code: Select all

``````#include<stdio.h>
#include<string.h>

#define mm(a,b) memset((a),(b),sizeof(a))

#define MAX 11

char grid[MAX][MAX];
char rob[MAX][MAX];

int N,M,cnt;

void visit(int i,int j)
{
int flag=0;
while(1)
{
flag=0;
if(i-1>=0 && grid[i-1][j]!='X' && rob[i-1][j]!='0')			//North
{
i--;
rob[i][j]=grid[i][j];
++cnt;
flag=1;
}
if(flag)
continue;
if(j+1<M && grid[i][j+1]!='X' && rob[i][j+1]!='0')			//East
{
j++;
rob[i][j]=grid[i][j];
cnt++;
flag=1;
}
if(flag)
continue;
if(i+1<N && grid[i+1][j]!='X' && rob[i+1][j]!='0')			//South
{
i++;
rob[i][j]=grid[i][j];
cnt++;
flag=1;
}
if(flag)
continue;
if(j-1>=0 && grid[i][j-1]!='X' && rob[i][j-1]!='0')			//West
{
j--;
rob[i][j]=grid[i][j];
cnt++;
flag=1;
}
if(flag==0)
return;
}
}

int main()
{
int i,j,sc,sr,flag=0;
char temp;
//freopen("10500.in","r",stdin);
//freopen("10500.out","w",stdout);
while(scanf("%d %d",&N,&M),N!=0 && M!=0)
{
scanf("%d %d\n",&sr,&sc);
mm(grid,0);
mm(rob,0);
for(i=0;i<N;i++)
{
j=0;
while(j!=M)
{
scanf("%c",&temp);
if(temp!='X' && temp!='0')
continue;
grid[i][j]=temp;
rob[i][j]='?';
j++;
}
}
cnt=0;
rob[sr-1][sc-1]='0';
visit(sr-1,sc-1);
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
if(rob[i][j]=='0')
{
if(i-1>=0)
rob[i-1][j]=grid[i-1][j];
if(i+1<N)
rob[i+1][j]=grid[i+1][j];
if(j-1>=0)
rob[i][j-1]=grid[i][j-1];
if(j+1<M)
rob[i][j+1]=grid[i][j+1];
}
}
}
if(flag)
puts("");
for(i=0;i<M;i++)
printf("|---");
printf("|\n");
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
printf("| %c ",rob[i][j]);
puts("|");
for(j=0;j<M;j++)
printf("|---");
printf("|\n");
}
printf("\nNUMBER OF MOVEMENTS: %d\n",cnt);
flag=1;
}
return 0;
}
``````

Posted: Tue Jul 19, 2005 8:31 am
Hi all,

Posted: Wed Oct 26, 2005 5:49 pm
Your output definitely look wrong. You did not read the problem description properly.

Code: Select all

``````
|---|---|---|---|---|
| ? | X | 0 | 0 | X |
|---|---|---|---|---|
| ? | X | 0 | 0 | X |
|---|---|---|---|---|
| X | 0 | X | 0 | X |
|---|---|---|---|---|
| X | 0 | 0 | 0 | X |
|---|---|---|---|---|
| ? | X | X | X | ? |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 7

|---|---|---|---|---|
| 0 | 0 | X | ? | ? |
|---|---|---|---|---|
| X | X | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 1

|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | X | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | X | 0 | X | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | X | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|

NUMBER OF MOVEMENTS: 0

|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|

NUMBER OF MOVEMENTS: 99

|---|
| 0 |
|---|

NUMBER OF MOVEMENTS: 0

|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 4

|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|

NUMBER OF MOVEMENTS: 4

``````

Posted: Wed Nov 23, 2005 11:00 am
Yes, sorry. I didn't check the posted output properly. All characters should be centered as in roticv's output. Both outputs are identical ( I removed the additional empty lines) but it's still P.E.?!?!

Code: Select all

``````|---|---|---|---|---|
| ? | X | 0 | 0 | X |
|---|---|---|---|---|
| ? | X | 0 | 0 | X |
|---|---|---|---|---|
| X | 0 | X | 0 | X |
|---|---|---|---|---|
| X | 0 | 0 | 0 | X |
|---|---|---|---|---|
| ? | X | X | X | ? |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 7

|---|---|---|---|---|
| 0 | 0 | X | ? | ? |
|---|---|---|---|---|
| X | X | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 1

|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | X | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | X | 0 | X | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | X | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|

NUMBER OF MOVEMENTS: 0

|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|

NUMBER OF MOVEMENTS: 99

|---|
| 0 |
|---|

NUMBER OF MOVEMENTS: 0

|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 4

|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|

NUMBER OF MOVEMENTS: 4
``````

### 10500 PE

Posted: Sat Jun 17, 2006 12:36 am
could any one please tell me what's wrong in this code that I got
P.E:

#include<iostream.h>
#include<stdio.h>
//#include<fstream.h>

enum status{con,stop};

void main(){
status st;
char board[11][11],map[11][11],str[10],vis[11][11];
int i,k,j,m,n,steps;
int curX,curY;

//ifstream cin("10500.in");
cin>>n>>m;
while(n!=0 && m!=0){
cin>>curX>>curY;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cin>>board[j];
map[j]='?';
vis[j]=0;
}
cin.getline(str,10);
}
map[curX][curY]='0';
vis[curX][curY]=1;
//perX=curX;
//perY=curY;
st=con;
steps=0;
while(st==con){
if(curX>1)map[curX-1][curY]=board[curX-1][curY];
if(curY>1)map[curX][curY-1]=board[curX][curY-1];
if(curX<n)map[curX+1][curY]=board[curX+1][curY];
if(curY<m)map[curX][curY+1]=board[curX][curY+1];

if((curX-1)>=1 && /*curX-1!=perX*/vis[curX-1][curY]!=1){
if(board[curX-1][curY]=='0'){
// perX=curX;
// perY=curY;

curX--;
steps++;
map[curX][curY]='0';
vis[curX][curY]=1;
continue;
}//else{
// map[curX-1][curY]='X';
//}
}
if((curY+1)<=m && /*curY+1!=perY*/vis[curX][curY+1]!=1){
if(board[curX][curY+1]=='0'){
// perX=curX;
// perY=curY;
curY++;
steps++;
map[curX][curY]='0';
vis[curX][curY]=1;
continue;
}//else{
// map[curX][curY+1]='X';
//}
}
if((curX+1)<=n && /*urX+1!=perX*/vis[curX+1][curY]!=1){
if(board[curX+1][curY]=='0'){
//perX=curX;
//perY=curY;
curX++;
steps++;
map[curX][curY]='0';
vis[curX][curY]=1;
continue;
}//else{
// map[curX+1][curY]='X';
// }
}
if((curY-1)>=1 && /*curY-1!=perY*/vis[curX][curY-1]!=1){
if(board[curX][curY-1]=='0'){
//perX=curX;
//perY=curY;
curY--;
steps++;
map[curX][curY]='0';
vis[curX][curY]=1;
continue;
}//else{
// map[curX][curY-1]='X';
// }
}
st=stop;
}
//cout<<endl;
for(i=1;i<=m;i++)
cout<<"|---";
cout<<"|"<<endl;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++)
cout<<"| "<<map[j]<<" ";
cout<<"|"<<endl;
for(k=1;k<=m;k++)
cout<<"|---";
cout<<"|"<<endl;

}

cout<<endl;
cout<<"NUMBER OF MOVEMENTS: "<<steps<<endl<<endl;
cin>>n>>m;
}
}

### Re: 10500 PE

Posted: Sun Jun 18, 2006 7:15 pm
farzane wrote:could any one please tell me what's wrong in this code that I got
P.E:
problem statement wrote:The application outputs an empty line, followed by the robot map, an empty line, and a line containing a message of the movements needed to reach that map.
What are those two endl in your code for?
farzane's code wrote:cout<<"NUMBER OF MOVEMENTS: "<<steps<<endl<<endl;

Posted: Mon Jun 19, 2006 11:43 pm
I think this two endl are needed.But I also tried your suggestion,still got PE

Posted: Tue Jun 20, 2006 3:00 am
Martin is right, you don't need both. You get an extra blank line at the end of the output and you are missing the leading blank line. Please remove the code after you get AC.

### 10500

Posted: Wed Aug 23, 2006 11:17 am
Hello All,
I've got several WA for the problem 10500. Someone plz help me to find out my error. What i'm missing ?? My code passed all the input given in the other threads. Plz help me. Here is my code. Thanks in advance.

Code: Select all

``````
#include<stdio.h>
#include<string.h>

#define mm(a,b) memset((a),(b),sizeof(a))

#define MAX 100

char grid[MAX][MAX];
char rob[MAX][MAX];

int N,M,cnt;

void visit(int i,int j)
{
int flag=0;
while(1)
{
flag=0;
if(i-1>=0 && grid[i-1][j]!='X' && rob[i-1][j]!='0')			//North
{
i--;
rob[i][j]=grid[i][j];
++cnt;
flag=1;
}
if(flag)
continue;
if(j+1<M && grid[i][j+1]!='X' && rob[i][j+1]!='0')			//East
{
j++;
rob[i][j]=grid[i][j];
cnt++;
flag=1;
}
if(flag)
continue;
if(i+1<N && grid[i+1][j]!='X' && rob[i+1][j]!='0')			//South
{
i++;
rob[i][j]=grid[i][j];
cnt++;
flag=1;
}
if(flag)
continue;
if(j-1>=0 && grid[i][j-1]!='X' && rob[i][j-1]!='0')			//West
{
j--;
rob[i][j]=grid[i][j];
cnt++;
flag=1;
}
if(flag==0)
break;
}
}

int main()
{
int i,j,sc,sr,flag=0;
char temp;
//freopen("10500.in","r",stdin);
//freopen("10500.out","w",stdout);
while(scanf("%d %d",&N,&M),N!=0 && M!=0)
{
scanf("%d %d\n",&sr,&sc);
mm(grid,0);
mm(rob,0);
for(i=0;i<N;i++)
{
j=0;
while(j!=M)
{
scanf("%c",&temp);
if(temp!='X' && temp!='0')
continue;
grid[i][j]=temp;
rob[i][j]='?';
j++;
}
}
cnt=0;
rob[sr-1][sc-1]='0';
visit(sr-1,sc-1);
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
if(rob[i][j]=='0')
{
if(i-1>=0)
rob[i-1][j]=grid[i-1][j];
if(i+1<N)
rob[i+1][j]=grid[i+1][j];
if(j-1>=0)
rob[i][j-1]=grid[i][j-1];
if(j+1<M)
rob[i][j+1]=grid[i][j+1];
}
}
}
if(flag)
puts("");
for(i=0;i<M;i++)
printf("|---");
printf("|\n");
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
printf("| %c ",rob[i][j]);
puts("|");
for(j=0;j<M;j++)
printf("|---");
printf("|\n");
}
printf("\nNUMBER OF MOVEMENTS: %d\n",cnt);
flag=1;
}
return 0;
}
``````

### Re: Pr# 10500 Robot maps !!!! WA !!!!!! Help Plz

Posted: Wed Aug 23, 2006 10:29 pm
There is already a thread on this problem. If there is a thread on a particular problem, please, use it to post your question and do not create a new one. (see http://online-judge.uva.es/board/viewto ... ight=10500, http://online-judge.uva.es/board/viewto ... ight=10500 and http://online-judge.uva.es/board/viewto ... ight=10500)
forum 'Volume CV' description wrote:All about problems in Volume CV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Posted: Thu Aug 24, 2006 9:44 am
Hi Martin Macko,
Forgot to search before posting !!!!! Sorry.... But where is my mistake in my code???? Thanks in advance.

### Re: Pr# 10500 Robot maps !!!! WA !!!!!! Help Plz

Posted: Sat Aug 26, 2006 9:07 pm
Chok wrote:Hello All,
I've got several WA for the problem 10500. Someone plz help me to find out my error. What i'm missing ?? My code passed all the input given in the other threads. Plz help me. Here is my code. Thanks in advance.
Chok's main() wrote:......if(flag)
.........puts("");
You should write an empty line before every test case.
The problem statement wrote:The application outputs an empty line, followed by the robot map, an empty line, and a line containing a message of the movements needed to reach that map.

Posted: Mon Aug 28, 2006 2:01 pm
Hi Martin Macko,
Thanks for your reply. But i've changed it, but still WA !!!!!

Posted: Tue Aug 29, 2006 11:02 pm
Chok wrote:Hi Martin Macko,
Thanks for your reply. But i've changed it, but still WA !!!!!
Ok, I've just found your bug. Try this:

Code: Select all

``````5 3
3 2
X X X
X 0 X
X 0 X
X 0 X
X X X
0 0``````
The correct output is:

Code: Select all

``````|---|---|---|
| ? | X | ? |
|---|---|---|
| X | 0 | X |
|---|---|---|
| X | 0 | X |
|---|---|---|
| ? | 0 | ? |
|---|---|---|
| ? | ? | ? |
|---|---|---|

NUMBER OF MOVEMENTS: 1``````

Posted: Sat Oct 13, 2007 5:37 pm
I've got several WA for the problem 10500.
Someone plz help me to find out my error.
thank you very much..

Code: Select all

``````remove after ac.
``````