#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> X = {-1, 0, 1, 0}, Y = {0, 1, 0, -1};
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> a(n);
for (auto &i : a)
cin >> i;
char c = a[0][0];
queue<pair<int, int>> q;
vector<vector<bool>> mp(n, vector<bool>(m));
q.push({0, 0}); mp[0][0] = true;
for (int z = 1; z < 10000; z++) {
queue<pair<int, int>> nq;
while (!q.empty()) {
auto [x, y] = q.front(); q.pop();
for (int i = 0; i < 4; i++) {
int nx = x + X[i], ny = y + Y[i];
if (0 <= min(nx, ny) && nx < n && ny < m && !mp[nx][ny] && a[nx][ny] != '.') {
mp[nx][ny] = true;
(c == a[nx][ny] ? q : nq).push({nx, ny});
}
}
}
if (nq.empty()) return cout << z, 0;
q = nq;
c = (c == 'F' ? 'R' : 'F');
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
912 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
7 ms |
860 KB |
Output is correct |
16 |
Correct |
8 ms |
1116 KB |
Output is correct |
17 |
Correct |
6 ms |
1040 KB |
Output is correct |
18 |
Correct |
4 ms |
916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
32 ms |
3952 KB |
Output is correct |
3 |
Incorrect |
34 ms |
35920 KB |
Output isn't correct |
4 |
Correct |
32 ms |
8684 KB |
Output is correct |
5 |
Incorrect |
15 ms |
20108 KB |
Output isn't correct |
6 |
Correct |
634 ms |
56012 KB |
Output is correct |
7 |
Correct |
2 ms |
888 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
13 |
Correct |
29 ms |
3952 KB |
Output is correct |
14 |
Correct |
18 ms |
2396 KB |
Output is correct |
15 |
Incorrect |
3 ms |
2652 KB |
Output isn't correct |
16 |
Correct |
14 ms |
1884 KB |
Output is correct |
17 |
Correct |
83 ms |
9400 KB |
Output is correct |
18 |
Incorrect |
7 ms |
9052 KB |
Output isn't correct |
19 |
Correct |
33 ms |
8528 KB |
Output is correct |
20 |
Incorrect |
8 ms |
7760 KB |
Output isn't correct |
21 |
Incorrect |
21 ms |
20872 KB |
Output isn't correct |
22 |
Incorrect |
19 ms |
20736 KB |
Output isn't correct |
23 |
Correct |
173 ms |
17500 KB |
Output is correct |
24 |
Incorrect |
15 ms |
20304 KB |
Output isn't correct |
25 |
Incorrect |
26 ms |
35868 KB |
Output isn't correct |
26 |
Correct |
303 ms |
27732 KB |
Output is correct |
27 |
Correct |
466 ms |
39228 KB |
Output is correct |
28 |
Correct |
628 ms |
55992 KB |
Output is correct |
29 |
Correct |
611 ms |
52864 KB |
Output is correct |
30 |
Correct |
527 ms |
50240 KB |
Output is correct |
31 |
Correct |
483 ms |
23892 KB |
Output is correct |
32 |
Correct |
395 ms |
37460 KB |
Output is correct |