Submission #260142

#TimeUsernameProblemLanguageResultExecution timeMemory
260142jdhAwesome Arrowland Adventure (eJOI19_adventure)C++17
38 / 100
1 ms512 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; map<char,ll> mp = { {'N',0},{'E',1},{'S',2},{'W',3} }; vector<tuple<ll,ll,char>> dirs = { {-1,0,'N'},{0,1,'E'},{1,0,'S'},{0,-1,'W'} }; int main(){ ios::sync_with_stdio(0); cin.tie(0); ll n,m; cin >> n >> m; vector<string> vs(n); for(ll i = 0; i < n; ++i) cin >> vs[i]; vector<vector<ll>> val(n,vector<ll>(m,-1)); set<tuple<ll,ll,ll>> sp; sp.emplace(0,0,0); while(!sp.empty()){ ll a,x,y; tie(a,x,y) = *begin(sp); sp.erase(begin(sp)); if(val[x][y] >= 0) continue; val[x][y] = a; if(x == n-1 and y == m-1) break; for(auto& dir : dirs){ ll dx,dy; char d; tie(dx,dy,d) = dir; ll x1 = x+dx,y1 = y+dy; if(0 <= x1 and x1 < n and 0 <= y1 and y1 < m){ if(val[x1][y1] == -1){ if(vs[x1][y1] != 'X' or (x1 == n-1 and y1 == m-1)){ ll delta = (mp[d]+4-mp[vs[x][y]])%4; sp.emplace(a+delta,x1,y1); } } } } } cout << val[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...