Submission #446761

#TimeUsernameProblemLanguageResultExecution timeMemory
446761fuad27Awesome Arrowland Adventure (eJOI19_adventure)C++14
22 / 100
8 ms4392 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define MAX 507 vector < vector < int >> g(MAX, vector < int > (MAX, 0)); vector < vector < int >> dist(MAX, vector < int > (MAX, -1)); int dx[4] = { 0, 1, 0 - 1 }, dy[4] = { -1, 0, 1, 0 }, n, m; void dj() { priority_queue < pair < int, pair < int, int >> , vector < pair < int, pair < int, int >> > , greater < pair < int, pair < int, int > > > > pq; pq.push(make_pair(0, make_pair(0, 0))); while (!pq.empty()) { int x = pq.top().second.first, y = pq.top().second.second, c = pq.top().first; pq.pop(); if (x < 0 || x >= m || y < 0 || y >= n || dist[y][x] != -1) continue; dist[y][x] = c; if (g[y][x] == -1) continue; for (int i = 0; i < 4; i++) pq.push(make_pair(c + i, make_pair(x + dx[(g[y][x] + i) % 4], y + dy[(g[y][x] + i) % 4]))); } } int32_t main() { cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { char c; cin >> c; if (c == 'N') g[i][j] = 0; if (c == 'E') g[i][j] = 1; if (c == 'S') g[i][j] = 2; if (c == 'W') g[i][j] = 3; else if (c == 'X') g[i][j] = -1; } } dj(); cout << dist[n - 1][m - 1] << endl; }
#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...