#include <bits/stdc++.h>
using namespace std;
int main(){
int h,w;
scanf("%d%d",&h,&w);
char grid[h+5][w+5];
for(int i=0;i<h;i++){
scanf("%s",grid[i]);
}
int r=0,f=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(grid[i][j]=='R')r++;
else if(grid[i][j]=='F')f++;
}
}
int ans=1;
queue<pair<int,int> > q;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
while(r!=0&&f!=0){
ans++;
q.push(make_pair(0,0));
if(grid[0][0]=='R'){
while(!q.empty()){
pair<int,int> cur=q.front();q.pop();
for(int i=0;i<4;i++){
int nx=cur.first+dx[i],ny=cur.second+dy[i];
if(0<=nx&&nx<h&&0<=ny&&ny<w&&grid[nx][ny]=='R'){
grid[nx][ny]='F';
r--; f++;
q.push(make_pair(nx,ny));
}
}
}
}else{
while(!q.empty()){
pair<int,int> cur=q.front();q.pop();
for(int i=0;i<4;i++){
int nx=cur.first+dx[i],ny=cur.second+dy[i];
if(0<=nx&&nx<h&&0<=ny&&ny<w&&grid[nx][ny]=='F'){
grid[nx][ny]='R';
f--; r++;
q.push(make_pair(nx,ny));
}
}
}
}
}
printf("%d",ans);
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:6: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:9:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",grid[i]);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
888 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
256 KB |
Output is correct |
4 |
Correct |
15 ms |
640 KB |
Output is correct |
5 |
Correct |
44 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
53 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
43 ms |
512 KB |
Output is correct |
13 |
Correct |
41 ms |
512 KB |
Output is correct |
14 |
Correct |
39 ms |
512 KB |
Output is correct |
15 |
Correct |
368 ms |
768 KB |
Output is correct |
16 |
Correct |
153 ms |
888 KB |
Output is correct |
17 |
Correct |
270 ms |
640 KB |
Output is correct |
18 |
Correct |
13 ms |
680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
970 ms |
476 KB |
Output is correct |
2 |
Execution timed out |
2045 ms |
2168 KB |
Time limit exceeded |
3 |
Execution timed out |
2049 ms |
16248 KB |
Time limit exceeded |
4 |
Execution timed out |
2044 ms |
4344 KB |
Time limit exceeded |
5 |
Execution timed out |
2045 ms |
9336 KB |
Time limit exceeded |
6 |
Execution timed out |
2061 ms |
16380 KB |
Time limit exceeded |
7 |
Correct |
668 ms |
384 KB |
Output is correct |
8 |
Correct |
969 ms |
424 KB |
Output is correct |
9 |
Correct |
110 ms |
384 KB |
Output is correct |
10 |
Correct |
296 ms |
384 KB |
Output is correct |
11 |
Correct |
209 ms |
384 KB |
Output is correct |
12 |
Correct |
1341 ms |
372 KB |
Output is correct |
13 |
Execution timed out |
2062 ms |
1792 KB |
Time limit exceeded |
14 |
Execution timed out |
2035 ms |
1152 KB |
Time limit exceeded |
15 |
Execution timed out |
2045 ms |
1280 KB |
Time limit exceeded |
16 |
Execution timed out |
2033 ms |
896 KB |
Time limit exceeded |
17 |
Execution timed out |
2033 ms |
4336 KB |
Time limit exceeded |
18 |
Execution timed out |
2054 ms |
4224 KB |
Time limit exceeded |
19 |
Execution timed out |
2037 ms |
4088 KB |
Time limit exceeded |
20 |
Execution timed out |
2005 ms |
3756 KB |
Time limit exceeded |
21 |
Execution timed out |
2041 ms |
9464 KB |
Time limit exceeded |
22 |
Execution timed out |
2015 ms |
9080 KB |
Time limit exceeded |
23 |
Execution timed out |
2045 ms |
7928 KB |
Time limit exceeded |
24 |
Execution timed out |
2047 ms |
9208 KB |
Time limit exceeded |
25 |
Execution timed out |
2058 ms |
15992 KB |
Time limit exceeded |
26 |
Correct |
82 ms |
12280 KB |
Output is correct |
27 |
Correct |
1869 ms |
16044 KB |
Output is correct |
28 |
Execution timed out |
2056 ms |
16196 KB |
Time limit exceeded |
29 |
Execution timed out |
2101 ms |
16080 KB |
Time limit exceeded |
30 |
Execution timed out |
2036 ms |
15736 KB |
Time limit exceeded |
31 |
Execution timed out |
2041 ms |
10408 KB |
Time limit exceeded |
32 |
Execution timed out |
2035 ms |
16180 KB |
Time limit exceeded |