#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<string> graph(n);
for (int i = 0; i < n; i ++) cin >> graph[i];
int cnt[n][m];
int inf = 0x3f3f3f3f;
memset(cnt, inf, sizeof(cnt));
cnt[0][0] = 1;
queue<pair<int, int> > que;
que.push(make_pair(0, 0));
while(! que.empty()){
pair<int, int> p = que.front();
que.pop();
for (int i = 0; i < 4; i ++){
int x = p.first + dx[i];
int y = p.second + dy[i];
if (x >= 0 && x < n && y >= 0 && y < m && cnt[x][y] > cnt[p.first][p.second] + (graph[x][y] != graph[p.first][p.second]) && (graph[x][y] == 'R' || graph[x][y] == 'F')){
que.push(make_pair(x, y));
cnt[x][y] = cnt[p.first][p.second] + (graph[x][y] != graph[p.first][p.second]);
}
}
}
int ans = 0;
for (int i = 0; i < n; i ++){
for (int j = 0; j < m; j ++) if (cnt[i][j] != inf) ans = max(ans, cnt[i][j]);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
1544 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
32 ms |
1100 KB |
Output is correct |
5 |
Correct |
18 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
636 KB |
Output is correct |
11 |
Correct |
4 ms |
516 KB |
Output is correct |
12 |
Correct |
65 ms |
748 KB |
Output is correct |
13 |
Correct |
13 ms |
716 KB |
Output is correct |
14 |
Correct |
15 ms |
716 KB |
Output is correct |
15 |
Correct |
132 ms |
1584 KB |
Output is correct |
16 |
Correct |
241 ms |
1568 KB |
Output is correct |
17 |
Correct |
151 ms |
1660 KB |
Output is correct |
18 |
Correct |
35 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
715 ms |
8152 KB |
Output is correct |
3 |
Execution timed out |
2060 ms |
80976 KB |
Time limit exceeded |
4 |
Execution timed out |
2065 ms |
19300 KB |
Time limit exceeded |
5 |
Correct |
195 ms |
45260 KB |
Output is correct |
6 |
Execution timed out |
2103 ms |
81092 KB |
Time limit exceeded |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
20 ms |
612 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
676 ms |
8200 KB |
Output is correct |
14 |
Correct |
345 ms |
4960 KB |
Output is correct |
15 |
Correct |
26 ms |
5296 KB |
Output is correct |
16 |
Correct |
602 ms |
3524 KB |
Output is correct |
17 |
Execution timed out |
2063 ms |
20716 KB |
Time limit exceeded |
18 |
Correct |
89 ms |
20236 KB |
Output is correct |
19 |
Execution timed out |
2091 ms |
19132 KB |
Time limit exceeded |
20 |
Execution timed out |
2071 ms |
17580 KB |
Time limit exceeded |
21 |
Execution timed out |
2091 ms |
47016 KB |
Time limit exceeded |
22 |
Correct |
190 ms |
45252 KB |
Output is correct |
23 |
Execution timed out |
2072 ms |
39424 KB |
Time limit exceeded |
24 |
Correct |
159 ms |
45636 KB |
Output is correct |
25 |
Correct |
499 ms |
80716 KB |
Output is correct |
26 |
Correct |
801 ms |
61744 KB |
Output is correct |
27 |
Correct |
1131 ms |
80740 KB |
Output is correct |
28 |
Execution timed out |
2070 ms |
81216 KB |
Time limit exceeded |
29 |
Execution timed out |
2092 ms |
81024 KB |
Time limit exceeded |
30 |
Execution timed out |
2089 ms |
79464 KB |
Time limit exceeded |
31 |
Execution timed out |
2067 ms |
52144 KB |
Time limit exceeded |
32 |
Execution timed out |
2096 ms |
80972 KB |
Time limit exceeded |