Submission #1026631

#TimeUsernameProblemLanguageResultExecution timeMemory
1026631kkkkkkkkTracks in the Snow (BOI13_tracks)C++14
82.50 / 100
2083 ms105260 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...