이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |