Submission #1025593

#TimeUsernameProblemLanguageResultExecution timeMemory
1025593vjudge1Awesome Arrowland Adventure (eJOI19_adventure)C++17
100 / 100
122 ms15548 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char pat[n][m]; for (int i=0;i<n;i++) for (int j=0;j<m;j++) cin >> pat[i][j]; priority_queue<pair<int, pair<int,int> > > pq; pq.push({0, {0, 0}}); int vis[n][m]; 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 (r>=n||c>=m||r<0||c<0) continue; if (vis[r][c]!=-1) continue; vis[r][c]=dist; if (pat[r][c]=='X') continue; if (pat[r][c]=='E') { pq.push({-dist, {r, c+1}}); pq.push({-(dist+1), {r+1, c}}); pq.push({-(dist+2), {r, c-1}}); pq.push({-(dist+3), {r-1, c}}); } else if (pat[r][c]=='N') { pq.push({-dist, {r-1, c}}); pq.push({-(dist+1), {r, c+1}}); pq.push({-(dist+2), {r+1, c}}); pq.push({-(dist+3), {r, c-1}}); } else if (pat[r][c]=='W') { pq.push({-dist, {r, c-1}}); pq.push({-(dist+1), {r-1, c}}); pq.push({-(dist+2), {r, c+1}}); pq.push({-(dist+3), {r+1, c}}); } else { pq.push({-dist, {r+1, c}}); pq.push({-(dist+1), {r, c-1}}); pq.push({-(dist+2), {r-1, c}}); pq.push({-(dist+3), {r, c+1}}); } } cout << vis[n-1][m-1]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...