답안 #999722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999722 2024-06-16T05:50:15 Z HasanV11010238 Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
219 ms 17396 KB
#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){
    priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;
    q.push({0, 0, 0});
    costs[0][0] = 0;
    vector<vector<int>> us(m, vector<int>(n, 0));
    while(!q.empty()){
        vector<int> u = q.top();
        q.pop();
        vector<vector<int>> moves = dir[ma[u[2]][u[1]]];
        for (auto el : moves){
            int x = el[0] + u[1], y = el[1] + u[2];
            if (check(x, y) && costs[y][x] > costs[u[2]][u[1]] + el[2]){
                costs[y][x] = costs[u[2]][u[1]] + el[2];
                if (us[y][x] == 0){
                    q.push({costs[y][x], x, y});
                }
                us[y][x];
            }
        }
    }
    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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 408 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 408 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 408 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 15 ms 600 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 14 ms 848 KB Output is correct
38 Correct 2 ms 1116 KB Output is correct
39 Correct 104 ms 4016 KB Output is correct
40 Correct 133 ms 3928 KB Output is correct
41 Correct 10 ms 3932 KB Output is correct
42 Correct 106 ms 4056 KB Output is correct
43 Correct 219 ms 17396 KB Output is correct
44 Correct 12 ms 3932 KB Output is correct