#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);
}
}
void print(vector<string>& grid) {
for(int i = 0; i < grid.size(); i++) {
for(int j = 0; j < grid[0].size(); j++) {
cout << grid[i][j];
}
cout << "\n";
}
cout << "\n";
}
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));
int sum = 0;
for(int i = 0; i < N; i++) {
/*print(grid);*/
for(int j = 0; j < M; j++) {
if(grid[i][j] == 'R' || grid[i][j] == 'F') {
floodfill(grid, visited, i, j, grid[i][j]);
visited[i][j] = true;
fill(visited.begin(), visited.end(), vector<bool>(N, false));
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;
| ~~^~~~~~~~~~~~~~~~~
tracks.cpp: In function 'void print(std::vector<std::__cxx11::basic_string<char> >&)':
tracks.cpp:23:19: 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]
23 | for(int i = 0; i < grid.size(); i++) {
| ~~^~~~~~~~~~~~~
tracks.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int j = 0; j < grid[0].size(); j++) {
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
196 ms |
16452 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Correct |
28 ms |
9992 KB |
Output is correct |
5 |
Incorrect |
53 ms |
1276 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 |
Incorrect |
3 ms |
592 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
336 KB |
Output isn't correct |
10 |
Incorrect |
59 ms |
828 KB |
Output isn't correct |
11 |
Correct |
7 ms |
3288 KB |
Output is correct |
12 |
Incorrect |
82 ms |
5448 KB |
Output isn't correct |
13 |
Incorrect |
51 ms |
1104 KB |
Output isn't correct |
14 |
Incorrect |
52 ms |
1104 KB |
Output isn't correct |
15 |
Correct |
396 ms |
3112 KB |
Output is correct |
16 |
Incorrect |
200 ms |
16664 KB |
Output isn't correct |
17 |
Incorrect |
394 ms |
4780 KB |
Output isn't correct |
18 |
Correct |
24 ms |
10056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2070 ms |
3316 KB |
Time limit exceeded |
2 |
Execution timed out |
2060 ms |
7108 KB |
Time limit exceeded |
3 |
Execution timed out |
2083 ms |
21580 KB |
Time limit exceeded |
4 |
Execution timed out |
2075 ms |
15612 KB |
Time limit exceeded |
5 |
Execution timed out |
2028 ms |
18760 KB |
Time limit exceeded |
6 |
Execution timed out |
2064 ms |
489292 KB |
Time limit exceeded |
7 |
Incorrect |
1797 ms |
3488 KB |
Output isn't correct |
8 |
Execution timed out |
2071 ms |
3256 KB |
Time limit exceeded |
9 |
Runtime error |
15 ms |
592 KB |
Execution killed with signal 6 |
10 |
Runtime error |
2 ms |
848 KB |
Execution killed with signal 6 |
11 |
Incorrect |
732 ms |
3356 KB |
Output isn't correct |
12 |
Incorrect |
83 ms |
1300 KB |
Output isn't correct |
13 |
Execution timed out |
2060 ms |
8636 KB |
Time limit exceeded |
14 |
Execution timed out |
2069 ms |
4292 KB |
Time limit exceeded |
15 |
Execution timed out |
2060 ms |
2640 KB |
Time limit exceeded |
16 |
Runtime error |
1508 ms |
4292 KB |
Execution killed with signal 6 |
17 |
Execution timed out |
2025 ms |
8128 KB |
Time limit exceeded |
18 |
Execution timed out |
2074 ms |
5456 KB |
Time limit exceeded |
19 |
Execution timed out |
2039 ms |
18684 KB |
Time limit exceeded |
20 |
Execution timed out |
2041 ms |
8448 KB |
Time limit exceeded |
21 |
Execution timed out |
2073 ms |
18760 KB |
Time limit exceeded |
22 |
Execution timed out |
2048 ms |
19016 KB |
Time limit exceeded |
23 |
Execution timed out |
2044 ms |
19688 KB |
Time limit exceeded |
24 |
Execution timed out |
2048 ms |
12796 KB |
Time limit exceeded |
25 |
Execution timed out |
2037 ms |
30536 KB |
Time limit exceeded |
26 |
Correct |
1364 ms |
977992 KB |
Output is correct |
27 |
Execution timed out |
2076 ms |
666420 KB |
Time limit exceeded |
28 |
Execution timed out |
2099 ms |
489036 KB |
Time limit exceeded |
29 |
Execution timed out |
2043 ms |
447632 KB |
Time limit exceeded |
30 |
Execution timed out |
2137 ms |
910500 KB |
Time limit exceeded |
31 |
Execution timed out |
2108 ms |
139512 KB |
Time limit exceeded |
32 |
Execution timed out |
2109 ms |
596552 KB |
Time limit exceeded |