답안 #881742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881742 2023-12-01T20:12:19 Z db_123 Awesome Arrowland Adventure (eJOI19_adventure) C++17
0 / 100
1 ms 348 KB
#include <iostream>
#include <vector>
#include <set>

using namespace std;

struct Info {
    int node;
    int cost;
    Info() = default;
    Info(int node, int cost) {
        this->node = node;
        this->cost = cost;
    }
    bool operator<(Info a2) const {
        if(cost == a2.cost) {
            return node<a2.node;
        }
        return cost<a2.cost;
    }
};

int n,m;
vector<vector<char>> ma;
vector<vector<Info>> graph;

void read() {
    cin>>n>>m;
    ma.resize(n+1, vector<char>(m+1));
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            cin>>ma[i][j];
        }
    }
}

void form_graph() {
    graph.resize(n*m+1);
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            vector<int> delta;
            if(ma[i][j] == 'N') {
                delta = {0, 1, 2, 3};
            }
            else if(ma[i][j] == 'E') {
                delta = {3, 0, 1, 2};
            }
            else if(ma[i][j] == 'S') {
                delta = {2, 3, 0, 1};
            }
            else {
                delta = {1, 2, 3, 0};
            }
            int curr_node = (i-1)*m + j;
            int node_dr = (i-1)*m + j + 1;
            int node_st = (i-1)*m + j - 1;
            int node_jos = i * m + j;
            int node_sus = (i-2)*m + j;
            if(i-1>0 && ma[i-1][j]!='X') {
                graph[curr_node].push_back(*new Info(node_sus, delta[0]));
            }
            if(j+1<=m && ((i==n && j+1==m-1) || ma[i][j+1]!='X')) {
                graph[curr_node].push_back(*new Info(node_dr, delta[1]));
            }
            if(i+1<=n && ((i==n-1 && j==m) || ma[i+1][j+1]!='X')) {
                graph[curr_node].push_back(*new Info(node_jos, delta[2]));
            }
            if(j-1>0 && ma[i][j-1]!='X') {
                graph[curr_node].push_back(*new Info(node_st, delta[3]));
            }
        }
    }
}

int dijkstra() {
    vector<int> dist(n*m+1, 1e9);
    set<Info> st;
    st.insert(*new Info(1, 0));
    dist[1] = 0;
    Info tp;
    while(!st.empty()) {
        tp = (*st.begin());
        st.erase(st.begin());

        for(auto it : graph[tp.node]) {
            if(dist[it.node] > dist[tp.node] + it.cost) {
                dist[it.node] = dist[tp.node] + it.cost;
                st.insert(*new Info(it.node, dist[it.node]));
            }
        }
    }
    return dist[n*m];
}

void solve() {
    form_graph();
    cout<<dijkstra();
}

int main() {

    read();
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -