제출 #891532

#제출 시각아이디문제언어결과실행 시간메모리
891532HasanV11010238Awesome Arrowland Adventure (eJOI19_adventure)C++17
50 / 100
2064 ms4472 KiB
#include <bits/stdc++.h> using namespace std; #define INF 1000000000 map<char, vector<vector<int>>> dir; int n, m; bool check(int x, int y){ if (x >= 0 && x < n && y >= 0 && y < m){ return true; } return false; } void init(){ dir['N'] = {{0, -1, 0},{1, 0, 1}, {0, 1, 2}, {-1, 0, 3}}; dir['E'] = {{0, -1, 3},{1, 0, 0}, {0, 1, 1}, {-1, 0, 2}}; dir['S'] = {{0, -1, 2},{1, 0, 3}, {0, 1, 0}, {-1, 0, 1}}; dir['W'] = {{0, -1, 1},{1, 0, 2}, {0, 1, 3}, {-1, 0, 0}}; dir['X'] = {}; } int bfs(vector<vector<char>> ma, vector<vector<int>> costs){ queue<vector<int>> q; q.push({0, 0}); costs[0][0] = 0; while(!q.empty()){ vector<int> u = q.front(); q.pop(); vector<vector<int>> moves = dir[ma[u[1]][u[0]]]; for (auto el : moves){ int x = el[0] + u[0], y = el[1] + u[1]; if (check(x, y) && costs[y][x] > costs[u[1]][u[0]] + el[2]){ costs[y][x] = costs[u[1]][u[0]] + el[2]; q.push({x, y}); } } } return costs[m - 1][n - 1]; } int main(){ cin>>m>>n; vector<vector<char>> ma; vector<vector<int>> costs; char r; for (int i = 0; i < m; i++){ ma.push_back({}); costs.push_back({}); for (int j = 0; j < n; j++){ cin>>r; ma[i].push_back(r); costs[i].push_back(INF); } } init(); int res = bfs(ma, costs); if (res == INF){ cout<<-1; } else{ cout<<res; } }
#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...