This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |