이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<deque>
#include<array>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<string> a(n + 2);
string c = "";
for(int i = 0; i <= m + 1; i++) c += "*";
a[0] = c;
a[n + 1] = c;
for(int i = 1; i <= n; i++){
cin >> a[i];
a[i] = "*" + a[i] + "*";
}
vector<vector<int>> b(n + 2, vector<int>(m + 2, -1));
deque<array<int, 2>> dq;
b[1][1] = 1;
int maxi = 1;
dq.push_back({1, 1});
vector<array<int, 2>> dir = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
while(!dq.empty()){
int x = dq.front()[0];
int y = dq.front()[1];
dq.pop_front();
for(auto d : dir){
int xd = x + d[0];
int yd = y + d[1];
if(b[xd][yd] == -1){
if(a[x][y] == a[xd][yd]){
dq.push_front({xd, yd});
b[xd][yd] = b[x][y];
}
else if(a[xd][yd] != '*'){
dq.push_back({xd, yd});
b[xd][yd] = b[x][y] + 1;
maxi = b[x][y] + 1;
}
}
}
}
cout << maxi << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |