#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] = (current_animal == 'R' ? 'F' : 'R');
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;
while(true) {
fill(visited.begin(), visited.end(), vector<bool>(N, false));
sum++;
floodfill(grid, visited, 0, 0, grid[0][0]);
/*print(grid);*/
bool foundF = false;
bool foundR = false;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
foundF |= (grid[i][j] == 'F');
foundR |= (grid[i][j] == 'R');
}
}
if(foundF ^ foundR) {
break;
}
}
cout << sum + 1 << 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 |
Execution timed out |
2054 ms |
15688 KB |
Time limit exceeded |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
20 ms |
11472 KB |
Output is correct |
5 |
Correct |
49 ms |
1104 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Execution timed out |
2099 ms |
592 KB |
Time limit exceeded |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Execution timed out |
2091 ms |
592 KB |
Time limit exceeded |
11 |
Correct |
5 ms |
3408 KB |
Output is correct |
12 |
Execution timed out |
2091 ms |
5196 KB |
Time limit exceeded |
13 |
Correct |
48 ms |
1128 KB |
Output is correct |
14 |
Correct |
48 ms |
1116 KB |
Output is correct |
15 |
Correct |
380 ms |
2632 KB |
Output is correct |
16 |
Execution timed out |
2064 ms |
15688 KB |
Time limit exceeded |
17 |
Execution timed out |
2052 ms |
3912 KB |
Time limit exceeded |
18 |
Correct |
22 ms |
11600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2054 ms |
3260 KB |
Time limit exceeded |
2 |
Execution timed out |
2047 ms |
8264 KB |
Time limit exceeded |
3 |
Execution timed out |
2065 ms |
20936 KB |
Time limit exceeded |
4 |
Execution timed out |
2062 ms |
15808 KB |
Time limit exceeded |
5 |
Execution timed out |
2005 ms |
17340 KB |
Time limit exceeded |
6 |
Execution timed out |
2055 ms |
507904 KB |
Time limit exceeded |
7 |
Execution timed out |
2064 ms |
3068 KB |
Time limit exceeded |
8 |
Execution timed out |
2060 ms |
3404 KB |
Time limit exceeded |
9 |
Execution timed out |
2039 ms |
336 KB |
Time limit exceeded |
10 |
Execution timed out |
2041 ms |
336 KB |
Time limit exceeded |
11 |
Correct |
886 ms |
3048 KB |
Output is correct |
12 |
Correct |
1597 ms |
1352 KB |
Output is correct |
13 |
Execution timed out |
2066 ms |
5516 KB |
Time limit exceeded |
14 |
Execution timed out |
2058 ms |
3928 KB |
Time limit exceeded |
15 |
Execution timed out |
2060 ms |
3408 KB |
Time limit exceeded |
16 |
Execution timed out |
2056 ms |
1104 KB |
Time limit exceeded |
17 |
Execution timed out |
2029 ms |
8116 KB |
Time limit exceeded |
18 |
Execution timed out |
2076 ms |
5456 KB |
Time limit exceeded |
19 |
Execution timed out |
2017 ms |
16272 KB |
Time limit exceeded |
20 |
Execution timed out |
2045 ms |
7700 KB |
Time limit exceeded |
21 |
Execution timed out |
2101 ms |
13384 KB |
Time limit exceeded |
22 |
Execution timed out |
2066 ms |
11968 KB |
Time limit exceeded |
23 |
Execution timed out |
2061 ms |
17056 KB |
Time limit exceeded |
24 |
Execution timed out |
2057 ms |
12040 KB |
Time limit exceeded |
25 |
Execution timed out |
2058 ms |
20808 KB |
Time limit exceeded |
26 |
Incorrect |
1366 ms |
976456 KB |
Output isn't correct |
27 |
Execution timed out |
2040 ms |
1048576 KB |
Time limit exceeded |
28 |
Execution timed out |
2097 ms |
554036 KB |
Time limit exceeded |
29 |
Execution timed out |
2101 ms |
558196 KB |
Time limit exceeded |
30 |
Execution timed out |
2165 ms |
1017748 KB |
Time limit exceeded |
31 |
Execution timed out |
2057 ms |
131668 KB |
Time limit exceeded |
32 |
Execution timed out |
2116 ms |
629308 KB |
Time limit exceeded |