이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |