제출 #730375

#제출 시각아이디문제언어결과실행 시간메모리
730375aykhnAwesome Arrowland Adventure (eJOI19_adventure)C++14
38 / 100
1 ms212 KiB
#include <bits/stdc++.h> /* author: aykhn 4/24/2023 */ using namespace std; typedef long long ll; #define OPT ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pii pair<int,int> #define pll pair<ll,ll> #define all(v) v.begin(), v.end() #define mpr make_pair #define pb push_back #define ts to_string #define fi first #define se second #define inf 0x3F3F3F3F #define infll 0x3F3F3F3F3F3F3F3FLL #define bpc __builtin_popcount #define print(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout<<endl; int main() { OPT; ll n, m; cin >> n >> m; vector<vector<char>> v(n, vector<char> (m)); vector<vector<ll>> dist(n, vector<ll> (m, inf)); for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { cin >> v[i][j]; if (v[i][j] == 'X') dist[i][j] = -inf; } } dist[n - 1][m - 1] = inf; priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>> pq; dist[0][0] = 0; pq.push(mpr(0, mpr(0, 0))); ll a[4] = {-1, 0, 0, 1}; ll b[4] = {0, -1, 1, 0}; vector<vector<ll>> ways(26, vector<ll> (26, 0)); ways[4][18] = 1; ways[4][22] = 2; ways[4][13] = 3; ways[13][4] = 1; ways[13][18] = 2; ways[13][22] = 3; ways[18][22] = 1; ways[18][13] = 2; ways[18][4] = 3; ways[22][13] = 1; ways[22][4] = 2; ways[22][18] = 3; while (!pq.empty()) { ll x = pq.top().se.fi; ll y = pq.top().se.se; ll w = pq.top().fi; pq.pop(); for (ll i = 0; i < 4; i++) { ll x1 = x + a[i]; ll y1 = y + b[i]; if (x1 >= n || x1 < 0 || y1 >= m || y1 < 0) continue; char ch; if (a[i] == -1 && b[i] == 0) ch = 'N'; else if (a[i] == 1 && b[i] == 0) ch = 'S'; else if (a[i] == 0 && b[i] == -1) ch = 'W'; else ch = 'E'; ll d = ways[v[x][y] - 'A'][ch - 'A']; if (d + w < dist[x1][y1]) { dist[x1][y1] = d + w; pq.push(mpr(dist[x1][y1], mpr(x1, y1))); } } } cout << (dist[n - 1][m - 1] != inf ? dist[n - 1][m - 1] : -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...