이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int dr[]={+1, 0, -1, 0};
int dc[]={0, +1, 0, -1};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
char tracks[n][m];
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
cin >> tracks[i][j];
priority_queue<pair<int, pair<int,int> > > pq;
pq.push({-1, {0,0}});
int vis[n][m], rez=1;
memset(vis, -1, sizeof(vis));
while (!pq.empty()) {
int r=pq.top().second.first, c=pq.top().second.second, dist=-pq.top().first;
pq.pop();
if (vis[r][c]!=-1) continue;
vis[r][c]=dist;
rez=max(rez, dist);
for (int i=0;i<4;i++) {
int nr=r+dr[i], nc=c+dc[i];
if (nr>=0&&nc>=0&&nr<n&&nc<m&&tracks[nr][nc]!='.') {
if (tracks[nr][nc]!=tracks[r][c]) pq.push({-(dist+1), {nr, nc}});
else pq.push({-dist, {nr, nc}});
}
}
}
cout << rez;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |