이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
int h, w; cin >> h >> w;
char meadow[h][w]; int depth[h][w];
for(int y=0; y<h; ++y) {
for(int x=0; x<w; ++x) {
cin >> meadow[y][x];
depth[y][x] = -1;
}
}
int deltaY[4] = {-1, 0, 1, 0};
int deltaX[4] = {0, 1, 0, -1};
deque<pair<int, int> > bfs;
pair<int, int> start; start.first = 0;
start.second = 0; bfs.push_front(start);
depth[0][0] = 1; int animals = 1;
while(!bfs.empty()) {
int y = bfs.front().first;
int x = bfs.front().second;
bfs.pop_front();
animals = max(animals, depth[y][x]);
for(int i=0; i<4; ++i) {
pair<int, int> next;
next.first = y + deltaY[i];
next.second = x + deltaX[i];
if(next.first >= 0 && next.first < h
&& next.second >= 0 && next.second < w
&& meadow[next.first][next.second] != '.'
&& depth[next.first][next.second] == -1) {
if(meadow[y][x] == meadow[next.first][next.second]) {
depth[next.first][next.second] = depth[y][x];
bfs.push_front(next);
}
else {
depth[next.first][next.second] = depth[y][x] + 1;
bfs.push_back(next);
}
}
}
}
cout << animals << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |