#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 4e3 + 5;
int h, w;
string s[N];
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
bool vs[N][N];
queue<pair<int, int>> q[2];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> h >> w;
for(int i = 0; i < h; ++i) cin >> s[i];
bool cur = (s[0][0] == 'F');
vs[0][0] = 1;
q[cur].emplace(0, 0);
int cnt = 0;
while(q[0].size() || q[1].size()) {
while(q[cur].size()) {
auto [u, v] = q[cur].front(); q[cur].pop();
for(int i = 0; i < 4; ++i) {
int x = u + dx[i];
int y = v + dy[i];
if(x < 0 || x >= h || y < 0 || y >= w) continue;
if(vs[x][y] || s[x][y] == '.') continue;
vs[x][y] = 1;
bool tmp = (s[x][y] == 'F');
q[tmp].emplace(x, y);
}
}
++cnt;
cur ^= 1;
}
cout << cnt;
return 0;
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:24:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
24 | auto [u, v] = q[cur].front(); q[cur].pop();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2908 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
4 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
1884 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
568 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
1628 KB |
Output is correct |
11 |
Correct |
2 ms |
1372 KB |
Output is correct |
12 |
Correct |
3 ms |
1884 KB |
Output is correct |
13 |
Correct |
2 ms |
1884 KB |
Output is correct |
14 |
Correct |
2 ms |
1884 KB |
Output is correct |
15 |
Correct |
7 ms |
3084 KB |
Output is correct |
16 |
Correct |
8 ms |
2908 KB |
Output is correct |
17 |
Correct |
6 ms |
2908 KB |
Output is correct |
18 |
Correct |
4 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15448 KB |
Output is correct |
2 |
Correct |
27 ms |
8792 KB |
Output is correct |
3 |
Correct |
139 ms |
49132 KB |
Output is correct |
4 |
Correct |
32 ms |
15392 KB |
Output is correct |
5 |
Correct |
114 ms |
30856 KB |
Output is correct |
6 |
Correct |
580 ms |
59088 KB |
Output is correct |
7 |
Correct |
7 ms |
16220 KB |
Output is correct |
8 |
Correct |
7 ms |
15452 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
7 ms |
15832 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
26 ms |
8540 KB |
Output is correct |
14 |
Correct |
15 ms |
5976 KB |
Output is correct |
15 |
Correct |
11 ms |
6492 KB |
Output is correct |
16 |
Correct |
13 ms |
3420 KB |
Output is correct |
17 |
Correct |
75 ms |
16724 KB |
Output is correct |
18 |
Correct |
45 ms |
16472 KB |
Output is correct |
19 |
Correct |
32 ms |
15324 KB |
Output is correct |
20 |
Correct |
33 ms |
14424 KB |
Output is correct |
21 |
Correct |
81 ms |
31828 KB |
Output is correct |
22 |
Correct |
119 ms |
30804 KB |
Output is correct |
23 |
Correct |
158 ms |
26344 KB |
Output is correct |
24 |
Correct |
95 ms |
31272 KB |
Output is correct |
25 |
Correct |
227 ms |
48952 KB |
Output is correct |
26 |
Correct |
317 ms |
39404 KB |
Output is correct |
27 |
Correct |
422 ms |
50704 KB |
Output is correct |
28 |
Correct |
581 ms |
59188 KB |
Output is correct |
29 |
Correct |
563 ms |
57524 KB |
Output is correct |
30 |
Correct |
478 ms |
56296 KB |
Output is correct |
31 |
Correct |
421 ms |
34384 KB |
Output is correct |
32 |
Correct |
395 ms |
49732 KB |
Output is correct |