#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int MAX=4e3+5;
const int INF=1e18;
const int MOD=1e9+7;
const int MAXL=32;
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
int g[MAX][MAX][2],h,w; // {T,R,B,L} , vertex-info (4)
bool chk(int x,int y) {
return (x>=0 && y>=0 && x<h && y<w && g[x][y][0]!=-1);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<setprecision(6)<<fixed;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin>>h>>w;
for(int i=0;i<h;i++) {
for(int j=0;j<w;j++) {
char s;
cin>>s;
if(s=='R') {
g[i][j][0]=0;
} else if(s=='F') {
g[i][j][0]=1;
} else {
g[i][j][0]=-1;
}
}
}
deque<tuple<int,int,int>>dq; //{x,y,dist}
dq.push_front({0,0,1});
int ans=1;
while(!dq.empty()) {
tuple<int,int,int>curr=dq.front();
dq.pop_front();
int x=get<0>(curr),y=get<1>(curr),d=get<2>(curr);
if(g[x][y][1]>0) {
continue;
}
g[x][y][1]=d;
ans=max(ans,d);
for(int i=0;i<4;i++) {
int nx=x+dx[i],ny=y+dy[i];
if(!chk(nx,ny) || g[nx][ny][1]>0) {
continue;
}
if(g[x][y][0]==g[nx][ny][0]) {
dq.push_front({nx,ny,d});
} else {
dq.push_back({nx,ny,d+1});
}
}
}
cout<<ans;
return 0;
}
Compilation message
tracks.cpp:5:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
5 | const int INF=1e18;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
4388 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
9 ms |
4052 KB |
Output is correct |
5 |
Correct |
3 ms |
2132 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
1740 KB |
Output is correct |
11 |
Correct |
3 ms |
1620 KB |
Output is correct |
12 |
Correct |
7 ms |
2268 KB |
Output is correct |
13 |
Correct |
3 ms |
2076 KB |
Output is correct |
14 |
Correct |
3 ms |
2132 KB |
Output is correct |
15 |
Correct |
16 ms |
4372 KB |
Output is correct |
16 |
Correct |
18 ms |
4308 KB |
Output is correct |
17 |
Correct |
12 ms |
4080 KB |
Output is correct |
18 |
Correct |
9 ms |
4072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
16084 KB |
Output is correct |
2 |
Correct |
67 ms |
17620 KB |
Output is correct |
3 |
Correct |
371 ms |
125736 KB |
Output is correct |
4 |
Correct |
96 ms |
37200 KB |
Output is correct |
5 |
Correct |
188 ms |
82816 KB |
Output is correct |
6 |
Correct |
923 ms |
162888 KB |
Output is correct |
7 |
Correct |
8 ms |
16852 KB |
Output is correct |
8 |
Correct |
8 ms |
16084 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
7 ms |
16468 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
63 ms |
17596 KB |
Output is correct |
14 |
Correct |
42 ms |
11068 KB |
Output is correct |
15 |
Correct |
27 ms |
12108 KB |
Output is correct |
16 |
Correct |
30 ms |
6892 KB |
Output is correct |
17 |
Correct |
152 ms |
40140 KB |
Output is correct |
18 |
Correct |
105 ms |
39648 KB |
Output is correct |
19 |
Correct |
97 ms |
37140 KB |
Output is correct |
20 |
Correct |
88 ms |
34260 KB |
Output is correct |
21 |
Correct |
238 ms |
85708 KB |
Output is correct |
22 |
Correct |
184 ms |
82736 KB |
Output is correct |
23 |
Correct |
300 ms |
71040 KB |
Output is correct |
24 |
Correct |
211 ms |
83916 KB |
Output is correct |
25 |
Correct |
499 ms |
125604 KB |
Output is correct |
26 |
Correct |
562 ms |
258256 KB |
Output is correct |
27 |
Correct |
715 ms |
204712 KB |
Output is correct |
28 |
Correct |
921 ms |
162912 KB |
Output is correct |
29 |
Correct |
916 ms |
155736 KB |
Output is correct |
30 |
Correct |
828 ms |
181356 KB |
Output is correct |
31 |
Correct |
766 ms |
94604 KB |
Output is correct |
32 |
Correct |
672 ms |
194304 KB |
Output is correct |