#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
void floodfill(vector<string>& grid, vector<vector<bool>>& visited, int i, int j, char current_animal) {
if(i < 0 || j < 0 || i >= grid.size() || j >= grid[0].size()) return;
if(grid[i][j] != current_animal && grid[i][j] != '#') return;
if(visited[i][j]) return;
visited[i][j] = true;
grid[i][j] = '#';
for(int k = 0; k < 4; k++) {
floodfill(grid, visited, i + dx[k], j + dy[k], current_animal);
}
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N, M; cin >> N >> M;
vector<string> grid(N); for(auto &x : grid) cin >> x;
vector<vector<bool>> visited(N, vector<bool>(N, false));
char current_animal = grid[0][0];
int sum = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(grid[i][j] == current_animal) {
floodfill(grid, visited, i, j, current_animal);
visited[i][j] = true;
fill(visited.begin(), visited.end(), vector<bool>(N, false));
current_animal = (current_animal == 'R' ? 'F' : 'R');
sum++;
}
}
}
cout << sum << endl;
}
Compilation message
tracks.cpp: In function 'void floodfill(std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::vector<bool> >&, int, int, char)':
tracks.cpp:10:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | if(i < 0 || j < 0 || i >= grid.size() || j >= grid[0].size()) return;
| ~~^~~~~~~~~~~~~~
tracks.cpp:10:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | if(i < 0 || j < 0 || i >= grid.size() || j >= grid[0].size()) return;
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
211 ms |
16748 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
4 |
Correct |
24 ms |
10064 KB |
Output is correct |
5 |
Incorrect |
51 ms |
1336 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
336 KB |
Output isn't correct |
10 |
Incorrect |
49 ms |
848 KB |
Output isn't correct |
11 |
Correct |
7 ms |
3408 KB |
Output is correct |
12 |
Incorrect |
69 ms |
5528 KB |
Output isn't correct |
13 |
Incorrect |
50 ms |
1316 KB |
Output isn't correct |
14 |
Incorrect |
50 ms |
1352 KB |
Output isn't correct |
15 |
Correct |
378 ms |
3104 KB |
Output is correct |
16 |
Incorrect |
197 ms |
16712 KB |
Output isn't correct |
17 |
Incorrect |
338 ms |
4936 KB |
Output isn't correct |
18 |
Correct |
24 ms |
10064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2059 ms |
3204 KB |
Time limit exceeded |
2 |
Execution timed out |
2055 ms |
8620 KB |
Time limit exceeded |
3 |
Execution timed out |
2074 ms |
21576 KB |
Time limit exceeded |
4 |
Execution timed out |
2059 ms |
19664 KB |
Time limit exceeded |
5 |
Execution timed out |
2007 ms |
18884 KB |
Time limit exceeded |
6 |
Execution timed out |
2060 ms |
547724 KB |
Time limit exceeded |
7 |
Incorrect |
1823 ms |
3656 KB |
Output isn't correct |
8 |
Execution timed out |
2066 ms |
3228 KB |
Time limit exceeded |
9 |
Runtime error |
9 ms |
592 KB |
Execution killed with signal 6 |
10 |
Runtime error |
2 ms |
848 KB |
Execution killed with signal 11 |
11 |
Incorrect |
727 ms |
3324 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
336 KB |
Output isn't correct |
13 |
Execution timed out |
2054 ms |
8692 KB |
Time limit exceeded |
14 |
Execution timed out |
2069 ms |
5192 KB |
Time limit exceeded |
15 |
Execution timed out |
2063 ms |
1872 KB |
Time limit exceeded |
16 |
Runtime error |
1192 ms |
4344 KB |
Execution killed with signal 6 |
17 |
Execution timed out |
2045 ms |
10864 KB |
Time limit exceeded |
18 |
Execution timed out |
2062 ms |
5456 KB |
Time limit exceeded |
19 |
Execution timed out |
2059 ms |
15932 KB |
Time limit exceeded |
20 |
Execution timed out |
2059 ms |
5324 KB |
Time limit exceeded |
21 |
Execution timed out |
2017 ms |
15104 KB |
Time limit exceeded |
22 |
Execution timed out |
2032 ms |
20508 KB |
Time limit exceeded |
23 |
Execution timed out |
2043 ms |
19568 KB |
Time limit exceeded |
24 |
Execution timed out |
2040 ms |
12804 KB |
Time limit exceeded |
25 |
Execution timed out |
2020 ms |
33168 KB |
Time limit exceeded |
26 |
Correct |
1419 ms |
982100 KB |
Output is correct |
27 |
Execution timed out |
2087 ms |
713156 KB |
Time limit exceeded |
28 |
Execution timed out |
2080 ms |
523368 KB |
Time limit exceeded |
29 |
Execution timed out |
2089 ms |
594376 KB |
Time limit exceeded |
30 |
Execution timed out |
2104 ms |
851528 KB |
Time limit exceeded |
31 |
Execution timed out |
2016 ms |
132560 KB |
Time limit exceeded |
32 |
Execution timed out |
2103 ms |
608920 KB |
Time limit exceeded |