Submission #999821

#TimeUsernameProblemLanguageResultExecution timeMemory
999821vjudge1Awesome Arrowland Adventure (eJOI19_adventure)C++17
34 / 100
1 ms600 KiB
#include <bits/stdc++.h> // author : Pluton #define OPT ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int ll #define ll long long #define pb push_back #define arr array #define fi first #define se second #define rep(i,j,k) for(int i = j; i <= k; ++i) #define all(a) a.begin(),a.end() #define pii pair<int,int> using namespace std; const int INF = 1e18; struct BIT { int n; vector<int> ft; void init(int N) { n = N + 5; ft.assign(n + 5, 0); } void add(int pos, int val) { for (pos = pos + 1; pos <= n; pos += pos & -pos) ft[pos] += val; } int get(int pos, int res = 0) { for (pos = pos + 1; pos > 0; pos -= pos & -pos) res += ft[pos]; return res; } }; map<char,vector<vector<int>>>d; int n, m; bool f(int x,int y) { if(x < 0 || y < 0 || x >= n || y >= m) return false; return true; } const int N = 505; vector<vector<char>>g(N); vector<vector<int>>cost(N); void _() { d['N'] = {{0, -1, 0},{1, 0, 1}, {0, 1, 2}, {-1, 0, 3}}; d['E'] = {{0, -1, 3},{1, 0, 0}, {0, 1, 1}, {-1, 0, 2}}; d['S'] = {{0, -1, 2},{1, 0, 3}, {0, 1, 0}, {-1, 0, 1}}; d['W'] = {{0, -1, 1},{1, 0, 2}, {0, 1, 3}, {-1, 0, 0}}; d['X'] = {}; cin >> m >> n; for(int i = 0; i < m; ++i) { for(int j = 0; j < n; ++j) { char c; cin >> c; g[i].push_back(c); cost[i].push_back(INF); } } priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>>q; q.push({0,0,0}); cost[0][0] = 0; vector<vector<int>>vis(m,vector<int>(n,0)); while(!q.empty()) { vector<int>u = q.top(); q.pop(); auto move = d[g[u[2]][u[1]]]; for(auto e : move) { int x = e[0] + u[1]; int y = e[1] + u[2]; if(f(x, y) && cost[y][x] > cost[u[2]][u[1]] + e[2]) { cost[y][x] = cost[u[2]][u[1]] + e[2]; if (vis[y][x] == 0){ q.push({cost[y][x], x, y}); } vis[y][x] = 1; } } } cout << (cost[m - 1][n - 1] == INF ? -1 : cost[m - 1][n - 1]); } signed main() { OPT int tc = 1; while(tc--) { _(); } }
#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...