#include "bits/stdc++.h"
using namespace std;
int INF = 1e9;
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
clock_t startTime = clock();
int n, m;
cin >> n >> m;
vector<vector<char>> a(n, vector<char>(m, '.'));
auto nw = a;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
if (max(n, m) == 1) {
cout << 1;
return 0;
}
vector<pair<int, int>> can = {{0, 0}};
vector<vector<bool>> vis(n, vector<bool>(m));
char x = a[0][0];
nw[0][0] = x;
vis[0][0] = true;
int ans = 0;
cout << 1 << endl;
while (nw != a) {
ans++;
for (int p = 0; p < can.size(); p++) {
auto [i, j] = can[p];
for (int k = 0; k < 4; k++) {
int ii = i + dx[k];
int jj = j + dy[k];
if (min(ii, jj) < 0 or ii == n or jj == m) continue;
if (vis[ii][jj]) continue;
if (a[ii][jj] == x) {
can.emplace_back(ii, jj);
vis[ii][jj] = true;
nw[ii][jj] = x;
}
}
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < m; j++) {
// cout << nw[i][j];
// }
// cout << endl;
// }
// cout << endl;
x = (x == 'R' ? 'L' : 'R');
}
cout << ans;
#ifdef sunnitov
cerr << "\nTime: " << (int)((double)(clock() - startTime) / CLOCKS_PER_SEC * 1000);
#endif
}
/*
FFR.....
.FRRR...
.FFFFF..
..RRRFFR
.....FFF
*/
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int p = 0; p < can.size(); p++) {
| ~~^~~~~~~~~~~~
tracks.cpp:11:13: warning: unused variable 'startTime' [-Wunused-variable]
11 | clock_t startTime = clock();
| ^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2070 ms |
1108 KB |
Time limit exceeded |
2 |
Execution timed out |
2040 ms |
212 KB |
Time limit exceeded |
3 |
Execution timed out |
2069 ms |
212 KB |
Time limit exceeded |
4 |
Execution timed out |
2064 ms |
1748 KB |
Time limit exceeded |
5 |
Execution timed out |
2068 ms |
468 KB |
Time limit exceeded |
6 |
Execution timed out |
2074 ms |
212 KB |
Time limit exceeded |
7 |
Execution timed out |
2058 ms |
340 KB |
Time limit exceeded |
8 |
Execution timed out |
2068 ms |
340 KB |
Time limit exceeded |
9 |
Execution timed out |
2070 ms |
340 KB |
Time limit exceeded |
10 |
Execution timed out |
2059 ms |
468 KB |
Time limit exceeded |
11 |
Execution timed out |
2074 ms |
984 KB |
Time limit exceeded |
12 |
Execution timed out |
2068 ms |
468 KB |
Time limit exceeded |
13 |
Execution timed out |
2068 ms |
468 KB |
Time limit exceeded |
14 |
Execution timed out |
2070 ms |
468 KB |
Time limit exceeded |
15 |
Execution timed out |
2069 ms |
980 KB |
Time limit exceeded |
16 |
Execution timed out |
2069 ms |
1108 KB |
Time limit exceeded |
17 |
Execution timed out |
2064 ms |
852 KB |
Time limit exceeded |
18 |
Execution timed out |
2061 ms |
1876 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2058 ms |
980 KB |
Time limit exceeded |
2 |
Execution timed out |
2077 ms |
3788 KB |
Time limit exceeded |
3 |
Execution timed out |
2096 ms |
34228 KB |
Time limit exceeded |
4 |
Execution timed out |
2074 ms |
8396 KB |
Time limit exceeded |
5 |
Execution timed out |
2079 ms |
19384 KB |
Time limit exceeded |
6 |
Execution timed out |
2084 ms |
67020 KB |
Time limit exceeded |
7 |
Execution timed out |
2084 ms |
1108 KB |
Time limit exceeded |
8 |
Execution timed out |
2086 ms |
980 KB |
Time limit exceeded |
9 |
Execution timed out |
2086 ms |
596 KB |
Time limit exceeded |
10 |
Execution timed out |
2080 ms |
340 KB |
Time limit exceeded |
11 |
Execution timed out |
2084 ms |
980 KB |
Time limit exceeded |
12 |
Execution timed out |
2082 ms |
340 KB |
Time limit exceeded |
13 |
Execution timed out |
2082 ms |
3788 KB |
Time limit exceeded |
14 |
Execution timed out |
2064 ms |
2388 KB |
Time limit exceeded |
15 |
Execution timed out |
2071 ms |
2460 KB |
Time limit exceeded |
16 |
Execution timed out |
2059 ms |
1748 KB |
Time limit exceeded |
17 |
Execution timed out |
2062 ms |
9044 KB |
Time limit exceeded |
18 |
Execution timed out |
2071 ms |
8924 KB |
Time limit exceeded |
19 |
Execution timed out |
2074 ms |
8408 KB |
Time limit exceeded |
20 |
Execution timed out |
2081 ms |
7648 KB |
Time limit exceeded |
21 |
Execution timed out |
2067 ms |
20080 KB |
Time limit exceeded |
22 |
Execution timed out |
2056 ms |
19376 KB |
Time limit exceeded |
23 |
Execution timed out |
2080 ms |
17088 KB |
Time limit exceeded |
24 |
Execution timed out |
2037 ms |
19704 KB |
Time limit exceeded |
25 |
Execution timed out |
2066 ms |
34124 KB |
Time limit exceeded |
26 |
Incorrect |
626 ms |
157656 KB |
Output isn't correct |
27 |
Execution timed out |
2068 ms |
165584 KB |
Time limit exceeded |
28 |
Execution timed out |
2083 ms |
67072 KB |
Time limit exceeded |
29 |
Execution timed out |
2069 ms |
67056 KB |
Time limit exceeded |
30 |
Execution timed out |
2086 ms |
165000 KB |
Time limit exceeded |
31 |
Execution timed out |
2057 ms |
22656 KB |
Time limit exceeded |
32 |
Execution timed out |
2067 ms |
34232 KB |
Time limit exceeded |