#include <bits/stdc++.h>
using namespace std;
vector<vector<char>> grid(4001, vector<char>(4001));
vector<vector<bool>> visited(4001, vector<bool>(4001, false));
vector<pair<int, int>> delta = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
map<char, char> hm;
int n, m, steps = 0;
bool inBounds(int i, int j) {
if (i < 0 || i >= n || j < 0 || j >= m) return 0;
return 1;
}
void bfs() {
int i = n-1, j = m-1;
queue<pair<int, int>> q;
q.push({i, j});
vector<vector<bool>> bfsVisited(n, vector<bool>(m, false));
bfsVisited[i][j] = true;
while (!q.empty()) {
int currRow = q.front().first;
int currCol = q.front().second;
grid[currRow][currCol] = hm[grid[currRow][currCol]];
if (!visited[currRow][currCol]) {
visited[currRow][currCol] = true;
steps--;
}
q.pop();
for (int i = 0; i < 4; i++) {
int nextRow = currRow + delta[i].first;
int nextCol = currCol + delta[i].second;
if (inBounds(nextRow, nextCol)
&& !bfsVisited[nextRow][nextCol]
&& grid[nextRow][nextCol] != '.'
&& grid[nextRow][nextCol] != grid[currRow][currCol]) {
q.push({nextRow, nextCol});
bfsVisited[nextRow][nextCol] = true;
}
}
}
}
int main() {
cin >> n >> m;
hm['F'] = 'R';
hm['R'] = 'F';
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> grid[i][j];
if (grid[i][j] == '.') visited[i][j] = true;
else steps++;
}
}
int animals = 0;
while (steps > 0) {
animals++;
bfs();
}
cout << animals << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
18524 KB |
Output is correct |
2 |
Correct |
11 ms |
18264 KB |
Output is correct |
3 |
Correct |
12 ms |
18268 KB |
Output is correct |
4 |
Correct |
30 ms |
18524 KB |
Output is correct |
5 |
Correct |
73 ms |
18428 KB |
Output is correct |
6 |
Correct |
11 ms |
18264 KB |
Output is correct |
7 |
Correct |
12 ms |
18228 KB |
Output is correct |
8 |
Correct |
12 ms |
18268 KB |
Output is correct |
9 |
Correct |
13 ms |
18268 KB |
Output is correct |
10 |
Correct |
84 ms |
18448 KB |
Output is correct |
11 |
Correct |
17 ms |
18908 KB |
Output is correct |
12 |
Correct |
61 ms |
18524 KB |
Output is correct |
13 |
Correct |
78 ms |
18520 KB |
Output is correct |
14 |
Correct |
72 ms |
18444 KB |
Output is correct |
15 |
Correct |
427 ms |
18552 KB |
Output is correct |
16 |
Correct |
173 ms |
18520 KB |
Output is correct |
17 |
Correct |
431 ms |
18612 KB |
Output is correct |
18 |
Correct |
29 ms |
18524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2053 ms |
18628 KB |
Time limit exceeded |
2 |
Execution timed out |
2052 ms |
20196 KB |
Time limit exceeded |
3 |
Execution timed out |
2071 ms |
36440 KB |
Time limit exceeded |
4 |
Execution timed out |
2066 ms |
22664 KB |
Time limit exceeded |
5 |
Execution timed out |
2037 ms |
28264 KB |
Time limit exceeded |
6 |
Execution timed out |
2056 ms |
36344 KB |
Time limit exceeded |
7 |
Correct |
1820 ms |
18616 KB |
Output is correct |
8 |
Execution timed out |
2057 ms |
18628 KB |
Time limit exceeded |
9 |
Correct |
142 ms |
18268 KB |
Output is correct |
10 |
Correct |
348 ms |
18440 KB |
Output is correct |
11 |
Correct |
750 ms |
18732 KB |
Output is correct |
12 |
Correct |
1537 ms |
18280 KB |
Output is correct |
13 |
Execution timed out |
2028 ms |
20200 KB |
Time limit exceeded |
14 |
Execution timed out |
2033 ms |
19296 KB |
Time limit exceeded |
15 |
Execution timed out |
2052 ms |
19540 KB |
Time limit exceeded |
16 |
Execution timed out |
2040 ms |
19024 KB |
Time limit exceeded |
17 |
Execution timed out |
2059 ms |
22744 KB |
Time limit exceeded |
18 |
Execution timed out |
2040 ms |
22864 KB |
Time limit exceeded |
19 |
Execution timed out |
2037 ms |
22624 KB |
Time limit exceeded |
20 |
Execution timed out |
2032 ms |
22232 KB |
Time limit exceeded |
21 |
Execution timed out |
2096 ms |
28756 KB |
Time limit exceeded |
22 |
Execution timed out |
2007 ms |
28380 KB |
Time limit exceeded |
23 |
Execution timed out |
2039 ms |
27096 KB |
Time limit exceeded |
24 |
Execution timed out |
2013 ms |
28520 KB |
Time limit exceeded |
25 |
Execution timed out |
2029 ms |
36220 KB |
Time limit exceeded |
26 |
Correct |
747 ms |
32096 KB |
Output is correct |
27 |
Execution timed out |
2037 ms |
36176 KB |
Time limit exceeded |
28 |
Execution timed out |
2015 ms |
36156 KB |
Time limit exceeded |
29 |
Execution timed out |
2073 ms |
36180 KB |
Time limit exceeded |
30 |
Execution timed out |
2054 ms |
35884 KB |
Time limit exceeded |
31 |
Execution timed out |
2036 ms |
29868 KB |
Time limit exceeded |
32 |
Execution timed out |
2040 ms |
36176 KB |
Time limit exceeded |