Submission #650616

#TimeUsernameProblemLanguageResultExecution timeMemory
650616KenparAwesome Arrowland Adventure (eJOI19_adventure)C++17
100 / 100
185 ms14252 KiB
#include "bits/stdc++.h" using namespace std; #define ll long long #define endl '\n' const ll MOD = 1e9+7; const ll INF = 1e16; const ll MAX = 1e5+1; vector<vector<int>> rotation(200, vector<int>(4)); vector<vector<int>> moves = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; void solve(){ rotation['N'][0] = 1; rotation['N'][1] = 2; rotation['N'][2] = 3; rotation['N'][3] = 0; rotation['E'][0] = 0; rotation['E'][1] = 1; rotation['E'][2] = 2; rotation['E'][3] = 3; rotation['S'][0] = 3; rotation['S'][1] = 0; rotation['S'][2] = 1; rotation['S'][3] = 2; rotation['W'][0] = 2; rotation['W'][1] = 3; rotation['W'][2] = 0; rotation['W'][3] = 1; int n,m; cin>>n>>m; vector<vector<int>> dp(n, vector<int>(m, -1)); vector<vector<char>> arr(n, vector<char>(m)); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cin>>arr[i][j]; } } priority_queue<pair<int, pair<int,int>>, vector<pair<int, pair<int,int>>>, greater<pair<int, pair<int,int>>>> pq; pq.push({0,{0,0}}); while(!pq.empty()){ pair<int, pair<int,int>> top = pq.top(); pq.pop(); if(top.second.first < 0 || top.second.first >= n) continue; if(top.second.second < 0 || top.second.second >= m) continue; if(dp[top.second.first][top.second.second] != -1) continue; dp[top.second.first][top.second.second] = top.first; //cout<<top.second.first<<" "<<top.second.second<<" : "<<top.first<<endl; if(arr[top.second.first][top.second.second] == 'X') continue; for(int i = 0; i < 4; i++){ //cout<<" i: "<<i<<" "<<arr[top.second.first][top.second.second]<<" "<<rotation[arr[top.second.first][top.second.second]][i]<<endl; pq.push({top.first + rotation[arr[top.second.first][top.second.second]][i], {top.second.first + moves[i][0], top.second.second + moves[i][1]}}); } } cout<<dp[n-1][m-1]; } int main() { cin.tie(NULL); ios::sync_with_stdio(NULL); int t = 1; //cin >> t; while(t--){ solve(); } }
#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...