이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w;
cin >> h >> w;
char grid[h][w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> grid[i][j];
int ans = 0;
int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1};
int depth[h][w];
deque<pair<int, int>> trav;
memset(depth, 0, sizeof(depth));
depth[0][0] = 1; trav.push_back({0, 0});
while (!trav.empty()){
pair<int, int> curr = trav.front(); trav.pop_front();
ans = max(ans, depth[curr.first][curr.second]);
for (int i = 0; i < 4; i++){
int x = curr.first+dx[i]; int y = curr.second+dy[i];
if (x < 0 or x >= h or y < 0 or y >= w or grid[x][y] == '.' or depth[x][y] != 0) continue;
if (grid[x][y] == grid[curr.first][curr.second]){
depth[x][y] = depth[curr.first][curr.second];
trav.push_front({x, y});
}
else{
depth[x][y] = depth[curr.first][curr.second]+1;
trav.push_back({x, y});
}
}
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |