이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
string pic[4000];
int minLen[4000][4000];
int H, W;
int Y[4] = {0, 0, 1, -1}, X[4] = {1, -1, 0, 0};
bool inRec(int Y, int X){
return (Y > -1 && Y < H && X > -1 && X < W && pic[Y][X] != '.');
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> H >> W;
for (int i = 0; i < H; i++){
cin >> pic[i];
}
deque<pair<int, int>> Q; // {X, Y}
pair<int, int> on;
int M = 0;
Q.push_front({0, 0});
minLen[0][0] = 1;
while (!Q.empty()){
on = Q.front();
Q.pop_front();
M = max(M, minLen[on.second][on.first]);
for (int i = 0; i < 4; i++){
int onX = on.first + X[i], onY = on.second + Y[i];
if (inRec(onY, onX) && minLen[onY][onX] == 0){
if (pic[on.second][on.first] == pic[onY][onX]){
Q.push_front({onX, onY});
minLen[onY][onX] = minLen[on.second][on.first];
}
else{
Q.push_back({onX, onY});
minLen[onY][onX] = minLen[on.second][on.first] + 1;
}
}
}
}
cout << M;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |