This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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) {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |