이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[4002][4002];
int dist[4002][4002];
int dx[4]={1,-1,0,0};
int dy[4]={0, 0,1,-1};
int isok(int x, int y){
return (0<x)&&(x<=n)&&(0<y)&&(y<=m)&&(dist[x][y]==0);
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
cin>>a[i][j];
}
}
deque<pair<int, int>> q;
q.push_back({1, 1});
dist[1][1]=1;
int sol=0;
while(!q.empty()){
int x, y;
tie(x, y)=q.front();
q.pop_front();
for(int k=0;k<4;++k){
int nx=x+dx[k], ny=y+dy[k];
if(isok(nx, ny)){
if(a[nx][ny]=='.') continue;
if(a[nx][ny]==a[x][y]){
dist[nx][ny]=dist[x][y];
sol=max(sol, dist[nx][ny]);
q.push_front({nx, ny});
}
else{
dist[nx][ny]=dist[x][y]+1;
sol=max(sol, dist[nx][ny]);
q.push_back({nx, ny});
}
}
}
}
cout<<sol<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |