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