답안 #448503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448503 2021-07-30T10:29:40 Z mychecksedad Awesome Arrowland Adventure (eJOI19_adventure) C++17
34 / 100
5 ms 6348 KB
/* Author : Mychecksdead */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 505;
#define pii pair<int,int>
#define pb push_back
struct Edge{
    int x, y, w;
};

int n, m, dist[N][N];
char c;
vector<Edge> g[N][N];
bool vis[N][N];


int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> n >> m;
    int arr[4][2]={{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    for(int i = 0; i <= n+2; i++) for(int j = 0; j <= m+2; j++) {dist[i][j] = 1e9; vis[i][j] = 0;}
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> c;
            if(c == 'N'){
                for(int k = 0; k < 4; k++){

                    g[i][j].pb({i + arr[k][0], j + arr[k][1], k});
                }
            }else if(c == 'E'){
                for(int k = 0; k < 4; k++){
                    g[i][j].pb({i + arr[(k+1)%4][0], j + arr[(k+1)%4][1], k});
                }
            }else if(c == 'S'){
                for(int k = 0; k < 4; k++){
                    g[i][j].pb({i + arr[(k+2)%4][0], j + arr[(k+2)%4][1], k});
                }
            }else if(c == 'W'){
                for(int k = 0; k < 4; k++){
                    g[i][j].pb({i + arr[(k+3)%4][0], j + arr[(k+3)%4][1], k});
                }
            }
        }   
    }
    dist[1][1] = 0;
    priority_queue<pair<int, pii>> q;
    q.push({0, {1, 1}});

    while(!q.empty()){
        int x = q.top().second.first, y = q.top().second.second;
        q.pop();
        if(vis[x][y]) continue;
        vis[x][y] = 1;
        for(Edge u: g[x][y]){
            if(!vis[u.x][u.y] && dist[x][y] + u.w < dist[u.x][u.y]){
                dist[u.x][u.y] = dist[x][y] + u.w;
                q.push({-u.w, {u.x, u.y}});
            }
        }
    }
    cout << (dist[n][m] == 1e9 ? -1 : dist[n][m]);


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6348 KB Output is correct
2 Correct 4 ms 6248 KB Output is correct
3 Correct 4 ms 6348 KB Output is correct
4 Correct 4 ms 6348 KB Output is correct
5 Correct 4 ms 6348 KB Output is correct
6 Correct 4 ms 6348 KB Output is correct
7 Correct 4 ms 6312 KB Output is correct
8 Correct 4 ms 6348 KB Output is correct
9 Correct 4 ms 6312 KB Output is correct
10 Correct 4 ms 6316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6348 KB Output is correct
2 Correct 4 ms 6248 KB Output is correct
3 Correct 4 ms 6348 KB Output is correct
4 Correct 4 ms 6348 KB Output is correct
5 Correct 4 ms 6348 KB Output is correct
6 Correct 4 ms 6348 KB Output is correct
7 Correct 4 ms 6312 KB Output is correct
8 Correct 4 ms 6348 KB Output is correct
9 Correct 4 ms 6312 KB Output is correct
10 Correct 4 ms 6316 KB Output is correct
11 Correct 5 ms 6312 KB Output is correct
12 Correct 5 ms 6320 KB Output is correct
13 Correct 4 ms 6348 KB Output is correct
14 Correct 4 ms 6316 KB Output is correct
15 Correct 4 ms 6220 KB Output is correct
16 Correct 4 ms 6220 KB Output is correct
17 Correct 4 ms 6348 KB Output is correct
18 Correct 4 ms 6220 KB Output is correct
19 Correct 4 ms 6220 KB Output is correct
20 Correct 5 ms 6316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6308 KB Output is correct
2 Correct 4 ms 6316 KB Output is correct
3 Correct 4 ms 6312 KB Output is correct
4 Correct 4 ms 6220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6280 KB Output is correct
2 Incorrect 4 ms 6220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6348 KB Output is correct
2 Correct 4 ms 6248 KB Output is correct
3 Correct 4 ms 6348 KB Output is correct
4 Correct 4 ms 6348 KB Output is correct
5 Correct 4 ms 6348 KB Output is correct
6 Correct 4 ms 6348 KB Output is correct
7 Correct 4 ms 6312 KB Output is correct
8 Correct 4 ms 6348 KB Output is correct
9 Correct 4 ms 6312 KB Output is correct
10 Correct 4 ms 6316 KB Output is correct
11 Correct 5 ms 6312 KB Output is correct
12 Correct 5 ms 6320 KB Output is correct
13 Correct 4 ms 6348 KB Output is correct
14 Correct 4 ms 6316 KB Output is correct
15 Correct 4 ms 6220 KB Output is correct
16 Correct 4 ms 6220 KB Output is correct
17 Correct 4 ms 6348 KB Output is correct
18 Correct 4 ms 6220 KB Output is correct
19 Correct 4 ms 6220 KB Output is correct
20 Correct 5 ms 6316 KB Output is correct
21 Correct 5 ms 6308 KB Output is correct
22 Correct 4 ms 6316 KB Output is correct
23 Correct 4 ms 6312 KB Output is correct
24 Correct 4 ms 6220 KB Output is correct
25 Correct 4 ms 6280 KB Output is correct
26 Incorrect 4 ms 6220 KB Output isn't correct
27 Halted 0 ms 0 KB -