이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define INF 999999999
#define mod 3000017
using namespace std;
int n,m,viz[4005][4005],dist[4005][4005];
string a[4005];
const int dx[]={-1,0,1,0};
const int dy[]={0,1,0,-1};
struct point{
int x,y;
};
deque <point> q;
int lee(){
viz[0][0]=1;
dist[0][0]=1;
q.push_back({0,0});
while (!q.empty()){
point x=q.front();
q.pop_front();
for(int d=0;d<4;d++){
point newx={dx[d]+x.x,dy[d]+x.y};
if (newx.x>=0 && newx.y>=0 && newx.x<n && newx.y<m)
if (!viz[newx.x][newx.y])
if (a[newx.x][newx.y]!='.'){
viz[newx.x][newx.y]=1;
if (a[x.x][x.y]==a[newx.x][newx.y]){
dist[newx.x][newx.y]=dist[x.x][x.y];
q.push_front(newx);
}
else{
dist[newx.x][newx.y]=dist[x.x][x.y]+1;
q.push_back(newx);
}
}
}
}
int mx=0;
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
mx=max(mx,dist[i][j]);
return mx;
}
int main(){
cin>>n>>m;
for (int i=0;i<n;i++) cin>>a[i];
cout<<lee();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |