#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;
char graph[n][m];
for (int i = 0; i < n; i ++) for (int j = 0; j < m; j ++) cin >> graph[i][j];
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
229 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
28 ms |
1072 KB |
Output is correct |
5 |
Correct |
15 ms |
720 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 |
7 ms |
632 KB |
Output is correct |
11 |
Correct |
5 ms |
516 KB |
Output is correct |
12 |
Correct |
53 ms |
764 KB |
Output is correct |
13 |
Correct |
15 ms |
720 KB |
Output is correct |
14 |
Correct |
15 ms |
644 KB |
Output is correct |
15 |
Correct |
129 ms |
1544 KB |
Output is correct |
16 |
Correct |
237 ms |
1636 KB |
Output is correct |
17 |
Correct |
141 ms |
1612 KB |
Output is correct |
18 |
Correct |
32 ms |
1060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
656 ms |
8132 KB |
Output is correct |
3 |
Execution timed out |
2080 ms |
78692 KB |
Time limit exceeded |
4 |
Execution timed out |
2091 ms |
18980 KB |
Time limit exceeded |
5 |
Correct |
317 ms |
44228 KB |
Output is correct |
6 |
Execution timed out |
2086 ms |
78932 KB |
Time limit exceeded |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
19 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
651 ms |
8012 KB |
Output is correct |
14 |
Correct |
342 ms |
4744 KB |
Output is correct |
15 |
Correct |
34 ms |
5140 KB |
Output is correct |
16 |
Correct |
638 ms |
3488 KB |
Output is correct |
17 |
Execution timed out |
2097 ms |
20292 KB |
Time limit exceeded |
18 |
Correct |
148 ms |
19780 KB |
Output is correct |
19 |
Execution timed out |
2097 ms |
18812 KB |
Time limit exceeded |
20 |
Execution timed out |
2075 ms |
17220 KB |
Time limit exceeded |
21 |
Execution timed out |
2082 ms |
45764 KB |
Time limit exceeded |
22 |
Correct |
323 ms |
44328 KB |
Output is correct |
23 |
Execution timed out |
2086 ms |
38536 KB |
Time limit exceeded |
24 |
Correct |
279 ms |
44740 KB |
Output is correct |
25 |
Correct |
730 ms |
78560 KB |
Output is correct |
26 |
Correct |
932 ms |
60360 KB |
Output is correct |
27 |
Correct |
1338 ms |
78800 KB |
Output is correct |
28 |
Execution timed out |
2083 ms |
79060 KB |
Time limit exceeded |
29 |
Execution timed out |
2047 ms |
79164 KB |
Time limit exceeded |
30 |
Execution timed out |
2087 ms |
77412 KB |
Time limit exceeded |
31 |
Execution timed out |
2081 ms |
51484 KB |
Time limit exceeded |
32 |
Execution timed out |
2089 ms |
79096 KB |
Time limit exceeded |