이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxN = 4e3+10;
vector<int> xy = {1, 0, -1, 0}, yx = {0, 1, 0, -1};
bool vis[mxN][mxN];
int h, w;
bool valid(int a, int b) {
return (a >= 0 && a < h && b >= 0 && b < w && !vis[a][b]);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> h >> w;
int ans = 0;
vector<string> v(h);
for(int i = 0; i < h; i++) {
cin >> v[i];
}
deque<array<int, 3>> q;
q.push_back({1, 0, 0});
while(!q.empty()) {
int curr = q.front()[0], x = q.front()[1], y = q.front()[2];
ans = max(ans, curr);
vis[x][y] = true;
q.pop_front();
for(int k = 0; k < 4; k++) {
int a = x+xy[k], b = y+yx[k];
if(valid(a, b) && v[a][b] != '.') {
if(v[a][b] == v[x][y]) q.push_front({curr, a, b});
else q.push_back({curr+1, a, b});
}
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |