제출 #1060219

#제출 시각아이디문제언어결과실행 시간메모리
1060219ThommyDBAwesome Arrowland Adventure (eJOI19_adventure)C++17
100 / 100
150 ms14528 KiB
#include<bits/stdc++.h>

using namespace std;

int m, n;
vector<vector<char>> grid;

signed main(){
    cin >> m >> n;
    grid.resize(m, vector<char>(n));
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            cin >> grid[i][j];
        }
    }
    priority_queue<pair<int, pair<int, int>>> pq;
    pq.push({0, {0, 0}});
    vector<vector<int>> visited(m, vector<int>(n, -1));
    while(!pq.empty()){
        int a = -pq.top().first;
        int x = pq.top().second.first;
        int y = pq.top().second.second;
        pq.pop();
        if(x>n-1 || x<0 || y>m-1 || y<0)continue;
        if(visited[y][x]!=-1) continue;
        visited[y][x]=a;
        if(grid[y][x]=='X')continue;
        if(grid[y][x]=='E'){
            pq.push({-a, {x+1, y}});
            pq.push({-a-1, {x, y+1}});
            pq.push({-a-2, {x-1, y}});
            pq.push({-a-3, {x, y-1}});
        }
        else if(grid[y][x]=='S'){
            pq.push({-a-3, {x+1, y}});
            pq.push({-a, {x, y+1}});
            pq.push({-a-1, {x-1, y}});
            pq.push({-a-2, {x, y-1}});
        }
        else if(grid[y][x]=='W'){
            pq.push({-a-2, {x+1, y}});
            pq.push({-a-3, {x, y+1}});
            pq.push({-a, {x-1, y}});
            pq.push({-a-1, {x, y-1}});
        }
        else if(grid[y][x]=='N'){
            pq.push({-a-1, {x+1, y}});
            pq.push({-a-2, {x, y+1}});
            pq.push({-a-3, {x-1, y}});
            pq.push({-a, {x, y-1}});
        }
    }

    cout << visited[m-1][n-1] << "\n";

    /*for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            cout << grid[i][j] << " ";
        }
        cout << "\n";
    }
    cout << "\n";
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            cout << visited[i][j] << " ";
        }
        cout << "\n";
    }*/
}
#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...