#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
bool check(vector<string>& grid) {
for(int i = 0; i < (int) grid.size(); i++) {
for(int j = 0; j < (int) grid[0].size(); j++) {
if(grid[i][j] == 'F' || grid[i][j] == 'R') {
return false;
}
}
}
return true;
}
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;
while(!check(grid)) {
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:21: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]
21 | if(i < 0 || j < 0 || i >= grid.size() || j >= grid[0].size()) return;
| ~~^~~~~~~~~~~~~~
tracks.cpp:21:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if(i < 0 || j < 0 || i >= grid.size() || j >= grid[0].size()) return;
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2037 ms |
16700 KB |
Time limit exceeded |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
4 |
Correct |
26 ms |
10068 KB |
Output is correct |
5 |
Incorrect |
49 ms |
1232 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
8 |
Execution timed out |
2082 ms |
592 KB |
Time limit exceeded |
9 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
10 |
Execution timed out |
2047 ms |
848 KB |
Time limit exceeded |
11 |
Correct |
9 ms |
3340 KB |
Output is correct |
12 |
Execution timed out |
2041 ms |
5448 KB |
Time limit exceeded |
13 |
Incorrect |
50 ms |
1336 KB |
Output isn't correct |
14 |
Incorrect |
50 ms |
1256 KB |
Output isn't correct |
15 |
Correct |
391 ms |
3460 KB |
Output is correct |
16 |
Execution timed out |
2073 ms |
16544 KB |
Time limit exceeded |
17 |
Execution timed out |
2061 ms |
4684 KB |
Time limit exceeded |
18 |
Correct |
29 ms |
10064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2051 ms |
3176 KB |
Time limit exceeded |
2 |
Execution timed out |
2049 ms |
8640 KB |
Time limit exceeded |
3 |
Execution timed out |
2082 ms |
36120 KB |
Time limit exceeded |
4 |
Execution timed out |
2017 ms |
17892 KB |
Time limit exceeded |
5 |
Execution timed out |
2045 ms |
20700 KB |
Time limit exceeded |
6 |
Execution timed out |
2122 ms |
549300 KB |
Time limit exceeded |
7 |
Incorrect |
1891 ms |
3612 KB |
Output isn't correct |
8 |
Execution timed out |
2058 ms |
3280 KB |
Time limit exceeded |
9 |
Execution timed out |
2063 ms |
592 KB |
Time limit exceeded |
10 |
Execution timed out |
2067 ms |
592 KB |
Time limit exceeded |
11 |
Incorrect |
769 ms |
3144 KB |
Output isn't correct |
12 |
Incorrect |
90 ms |
1148 KB |
Output isn't correct |
13 |
Execution timed out |
2053 ms |
8552 KB |
Time limit exceeded |
14 |
Execution timed out |
2052 ms |
5176 KB |
Time limit exceeded |
15 |
Execution timed out |
2056 ms |
2640 KB |
Time limit exceeded |
16 |
Execution timed out |
2069 ms |
2896 KB |
Time limit exceeded |
17 |
Execution timed out |
2052 ms |
11508 KB |
Time limit exceeded |
18 |
Execution timed out |
2045 ms |
9552 KB |
Time limit exceeded |
19 |
Execution timed out |
2050 ms |
19476 KB |
Time limit exceeded |
20 |
Execution timed out |
2033 ms |
8680 KB |
Time limit exceeded |
21 |
Execution timed out |
2029 ms |
20296 KB |
Time limit exceeded |
22 |
Execution timed out |
2021 ms |
20536 KB |
Time limit exceeded |
23 |
Execution timed out |
2055 ms |
20912 KB |
Time limit exceeded |
24 |
Execution timed out |
2028 ms |
20816 KB |
Time limit exceeded |
25 |
Execution timed out |
2098 ms |
36504 KB |
Time limit exceeded |
26 |
Correct |
1470 ms |
983600 KB |
Output is correct |
27 |
Execution timed out |
2073 ms |
536524 KB |
Time limit exceeded |
28 |
Execution timed out |
2059 ms |
504760 KB |
Time limit exceeded |
29 |
Execution timed out |
2052 ms |
459384 KB |
Time limit exceeded |
30 |
Execution timed out |
2078 ms |
810380 KB |
Time limit exceeded |
31 |
Execution timed out |
2045 ms |
141556 KB |
Time limit exceeded |
32 |
Execution timed out |
2060 ms |
612264 KB |
Time limit exceeded |