#include <bits/stdc++.h>
using namespace std;
const int mxN=4e3;
int n, m, ans, nb[4][2]={{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
string g[mxN];
vector<array<int, 2>> tp[2];
__attribute__((always_inline)) bool a(int i, int j) {
return i>=0&&i<n&&j>=0&&j<m&&g[i][j]!='.';
}
void dfs(int i, int j) {
char pc=g[i][j];
g[i][j]='.';
for(int k=0; k<4; ++k) {
int ni=i+nb[k][0], nj=j+nb[k][1];
if(!a(ni, nj))
continue;
if(g[ni][nj]==pc)
dfs(ni, nj);
else
tp[ans&1^1].push_back({ni, nj});
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i=0; i<n; ++i)
cin >> g[i];
tp[0].push_back({0, 0});
for(; tp[ans&1].size(); ++ans) {
for(array<int, 2> u : tp[ans&1])
if(a(u[0], u[1]))
dfs(u[0], u[1]);
tp[ans&1].clear();
}
cout << ans;
}
Compilation message
tracks.cpp: In function 'void dfs(int, int)':
tracks.cpp:23:10: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
tp[ans&1^1].push_back({ni, nj});
~~~^~
tracks.cpp: At global scope:
tracks.cpp:9:37: warning: always_inline function might not be inlinable [-Wattributes]
__attribute__((always_inline)) bool a(int i, int j) {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1528 KB |
Output is correct |
2 |
Correct |
2 ms |
1528 KB |
Output is correct |
3 |
Correct |
2 ms |
1528 KB |
Output is correct |
4 |
Correct |
9 ms |
2788 KB |
Output is correct |
5 |
Correct |
4 ms |
2788 KB |
Output is correct |
6 |
Correct |
2 ms |
2788 KB |
Output is correct |
7 |
Correct |
2 ms |
2788 KB |
Output is correct |
8 |
Correct |
2 ms |
2788 KB |
Output is correct |
9 |
Correct |
2 ms |
2788 KB |
Output is correct |
10 |
Correct |
4 ms |
2788 KB |
Output is correct |
11 |
Correct |
4 ms |
2788 KB |
Output is correct |
12 |
Correct |
7 ms |
2788 KB |
Output is correct |
13 |
Correct |
4 ms |
2788 KB |
Output is correct |
14 |
Correct |
4 ms |
2788 KB |
Output is correct |
15 |
Correct |
13 ms |
2788 KB |
Output is correct |
16 |
Correct |
16 ms |
3008 KB |
Output is correct |
17 |
Correct |
9 ms |
3008 KB |
Output is correct |
18 |
Correct |
9 ms |
4220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4220 KB |
Output is correct |
2 |
Correct |
38 ms |
6108 KB |
Output is correct |
3 |
Correct |
198 ms |
38100 KB |
Output is correct |
4 |
Correct |
44 ms |
38100 KB |
Output is correct |
5 |
Correct |
153 ms |
42512 KB |
Output is correct |
6 |
Correct |
741 ms |
136248 KB |
Output is correct |
7 |
Correct |
4 ms |
136248 KB |
Output is correct |
8 |
Correct |
3 ms |
136248 KB |
Output is correct |
9 |
Correct |
4 ms |
136248 KB |
Output is correct |
10 |
Correct |
3 ms |
136248 KB |
Output is correct |
11 |
Correct |
3 ms |
136248 KB |
Output is correct |
12 |
Correct |
2 ms |
136248 KB |
Output is correct |
13 |
Correct |
37 ms |
136248 KB |
Output is correct |
14 |
Correct |
22 ms |
136248 KB |
Output is correct |
15 |
Correct |
15 ms |
136248 KB |
Output is correct |
16 |
Correct |
22 ms |
136248 KB |
Output is correct |
17 |
Correct |
106 ms |
136248 KB |
Output is correct |
18 |
Correct |
52 ms |
136248 KB |
Output is correct |
19 |
Correct |
42 ms |
136248 KB |
Output is correct |
20 |
Correct |
46 ms |
136248 KB |
Output is correct |
21 |
Correct |
114 ms |
136248 KB |
Output is correct |
22 |
Correct |
150 ms |
136248 KB |
Output is correct |
23 |
Correct |
191 ms |
136248 KB |
Output is correct |
24 |
Correct |
111 ms |
136248 KB |
Output is correct |
25 |
Correct |
259 ms |
136248 KB |
Output is correct |
26 |
Correct |
1204 ms |
901464 KB |
Output is correct |
27 |
Correct |
875 ms |
901464 KB |
Output is correct |
28 |
Correct |
744 ms |
901464 KB |
Output is correct |
29 |
Correct |
902 ms |
901464 KB |
Output is correct |
30 |
Correct |
780 ms |
901464 KB |
Output is correct |
31 |
Correct |
570 ms |
901464 KB |
Output is correct |
32 |
Correct |
965 ms |
901464 KB |
Output is correct |