#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
#define INF 1000000000
using namespace std;
typedef vector<short> vi;
typedef pair<int,int>ii;
int H,W;
char X;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int tis(vector<vi> x, int ani){
queue<ii>q;q.push(ii(0,0));
x[0][0]=-1;
bool vis[H+5][W+5]={false};
vis[0][0]=true;
while(!q.empty()){
int x1=q.front().first,y1=q.front().second;
q.pop();
for(int k=0;k<4;k++){
int nx=x1+dx[k],ny=y1+dy[k];
if(0<=nx&&nx<H&&0<=ny&&ny<W){
if(!vis[nx][ny]){
if(x[nx][ny]==-1||x[nx][ny]==ani){
vis[nx][ny]=true;
x[nx][ny]=-1;
q.push(ii(nx,ny));
}
}
}
}
}
if(!vis[H-1][W-1])return INF;
bool isDone=true;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(x[i][j]==1||x[i][j]==2){
isDone=false;break;
}
}
if(isDone)break;
}
if(isDone)return 0;
return 1+min(tis(x,1),tis(x,2));
}
int main(){
scanf("%d%d",&H,&W);
vector<vi> gr(H);
for(int i=0;i<H;i++){
vi xyz(W);
for(int j=0;j<W;j++){
xyz[j]=-1;
}
gr[i]=xyz;
}
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
scanf(" %c",&X);
if(X=='.')gr[i][j]=0;
if(X=='F')gr[i][j]=1;
if(X=='R')gr[i][j]=2;
}
}
/*
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
printf("%d",gr[i][j]);
}
printf("\n");
}
*/
printf("%d\n",1+tis(gr,gr[0][0]));
return 0;
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&H,&W);
~~~~~^~~~~~~~~~~~~~
tracks.cpp:62:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&X);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1921 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Runtime error |
1500 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Execution timed out |
2140 ms |
992532 KB |
Time limit exceeded |
4 |
Execution timed out |
2079 ms |
270512 KB |
Time limit exceeded |
5 |
Incorrect |
7 ms |
1280 KB |
Output isn't correct |
6 |
Runtime error |
1610 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Execution timed out |
2089 ms |
1049600 KB |
Time limit exceeded |
8 |
Execution timed out |
2063 ms |
349880 KB |
Time limit exceeded |
9 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
10 |
Runtime error |
1298 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
11 |
Execution timed out |
2056 ms |
274808 KB |
Time limit exceeded |
12 |
Runtime error |
1440 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
13 |
Incorrect |
8 ms |
1152 KB |
Output isn't correct |
14 |
Incorrect |
9 ms |
1152 KB |
Output isn't correct |
15 |
Runtime error |
1449 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
16 |
Runtime error |
1831 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
17 |
Runtime error |
1286 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
18 |
Execution timed out |
2033 ms |
247200 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
1020 KB |
Output isn't correct |
2 |
Runtime error |
1390 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Incorrect |
948 ms |
79708 KB |
Output isn't correct |
4 |
Incorrect |
235 ms |
38008 KB |
Output isn't correct |
5 |
Incorrect |
529 ms |
45808 KB |
Output isn't correct |
6 |
Execution timed out |
2049 ms |
363068 KB |
Time limit exceeded |
7 |
Incorrect |
7 ms |
896 KB |
Output isn't correct |
8 |
Incorrect |
6 ms |
896 KB |
Output isn't correct |
9 |
Execution timed out |
2095 ms |
938432 KB |
Time limit exceeded |
10 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
11 |
Incorrect |
9 ms |
768 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
13 |
Runtime error |
1358 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
14 |
Runtime error |
1221 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
15 |
Runtime error |
1057 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
16 |
Runtime error |
1026 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
17 |
Runtime error |
1288 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
18 |
Runtime error |
1248 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
19 |
Incorrect |
217 ms |
38172 KB |
Output isn't correct |
20 |
Incorrect |
190 ms |
18168 KB |
Output isn't correct |
21 |
Runtime error |
1549 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
22 |
Incorrect |
500 ms |
45320 KB |
Output isn't correct |
23 |
Runtime error |
1651 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
24 |
Incorrect |
547 ms |
46232 KB |
Output isn't correct |
25 |
Incorrect |
1014 ms |
79996 KB |
Output isn't correct |
26 |
Correct |
1221 ms |
61740 KB |
Output is correct |
27 |
Incorrect |
1483 ms |
80064 KB |
Output isn't correct |
28 |
Execution timed out |
2033 ms |
363108 KB |
Time limit exceeded |
29 |
Execution timed out |
2089 ms |
363104 KB |
Time limit exceeded |
30 |
Execution timed out |
2114 ms |
170852 KB |
Time limit exceeded |
31 |
Runtime error |
1740 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
32 |
Runtime error |
1983 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |