제출 #260123

#제출 시각아이디문제언어결과실행 시간메모리
260123jdhAwesome Arrowland Adventure (eJOI19_adventure)C++17
38 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; map<char,int> mp = { {'N',0},{'E',1},{'S',2},{'W',3} }; vector<tuple<int,int,char>> dirs = { {-1,0,'N'},{0,1,'E'},{1,0,'S'},{0,-1,'W'} }; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n,m; cin >> n >> m; vector<string> vs(n); for(int i = 0; i < n; ++i) cin >> vs[i]; vector<vector<int>> val(n,vector<int>(m,-1)); set<tuple<int,int,int>> sp; sp.emplace(0,0,0); while(!sp.empty()){ int a,x,y; tie(a,x,y) = *begin(sp); sp.erase(begin(sp)); if(x == n-1 and y == m-1){ cout << a; return 0; } if(val[x][y] == -1){ val[x][y] = a; for(auto& dir : dirs){ int dx,dy; char d; tie(dx,dy,d) = dir; int 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)){ int delta = (mp[d]+4-mp[vs[x][y]])%4; sp.emplace(a+delta,x1,y1); } } } } } } cout << -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...