제출 #586850

#제출 시각아이디문제언어결과실행 시간메모리
586850Markomafko972Awesome Arrowland Adventure (eJOI19_adventure)C++14
100 / 100
186 ms18156 KiB
#include <bits/stdc++.h> #define X first #define Y second using namespace std; int n, m; char c; int kol[502][502]; int dist[502][502]; set< pair<int, pair<int, int> > > s; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> c; if (c == 'N') kol[i][j] = 0; else if (c == 'E') kol[i][j] = 1; else if (c == 'S') kol[i][j] = 2; else if (c == 'W') kol[i][j] = 3; else kol[i][j] = -1; dist[i][j] = 1e9; if (i == 0 && j == 0) dist[i][j] = 0; s.insert({dist[i][j], {i, j}}); } } while (!s.empty()) { int cost = s.begin() -> first; pair<int, int> p = s.begin() -> second; s.erase(s.begin()); if (kol[p.X][p.Y] == -1) continue; for (int i = 0; i < 4; i++) { int x = p.X + dx[i]; int y = p.Y + dy[i]; if (x < 0 || y < 0 || x >= n || y >= m) continue; int novi = i-kol[p.X][p.Y]; if (novi < 0) novi += 4; if (cost+novi < dist[x][y]) { s.erase({dist[x][y], {x, y}}); dist[x][y] = cost+novi; s.insert({dist[x][y], {x, y}}); } } } if (dist[n-1][m-1] >= 1e9) cout << -1; else cout << dist[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...