답안 #959491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959491 2024-04-08T10:21:33 Z ivopav Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
116 ms 15872 KB
#include <bits/stdc++.h>
using namespace std;

char slje(char str){
    if (str=='S'){
        return 'W';
    }
    if (str=='E'){
        return 'S';
    }
    if (str=='N'){
        return 'E';
    }
    if (str=='W'){
        return 'N';
    }
    
}

int kor(char str1,char str2){
    int kol=0;
    while (str1!=str2){
        kol++;
        str1=slje(str1);
    }
    return kol;
}

struct dijktyp{
    int x;
    int y;
    int dist;
};

bool operator<(dijktyp pom,dijktyp pom2){
    if (pom.dist==pom2.dist){
        if (pom.x==pom2.x){
            return pom.y<pom2.y;
        }
        return pom.x<pom2.x;
    }
    return pom.dist>pom2.dist;
}

int main(){
    int n;
    int m;
    cin >> n >> m;
    vector<vector<char>> mat={};
    for (int i=0;i<n;i++){
        mat.push_back({});
        for (int j=0;j<m;j++){
            char unos;
            cin >> unos;
            mat[i].push_back(unos);
        }
    }
    priority_queue<dijktyp> dijklis={};
    dijklis.push({0,0,0});
    vector<vector<int>> distmat=vector<vector<int>>(n,vector<int>(m,-1));
    while (dijklis.size()>0){
        dijktyp pom=dijklis.top();
        dijklis.pop();
        int x=pom.x;
        int y=pom.y;
        int dist=pom.dist;
        if (y==n-1 && x==m-1){
            cout << dist << "\n";
            exit(0);
        }
        if (distmat[y][x]!=-1 || mat[y][x]=='X'){
            continue;
        }
        //cout << x << " " << y << " " << dist << "\n";
        distmat[y][x]=dist;
        if (y>0){
            dijklis.push({x,y-1,dist+kor(mat[y][x],'N')});
        }
        if (y<n-1){
            dijklis.push({x,y+1,dist+kor(mat[y][x],'S')});
        }
        if (x>0){
            dijklis.push({x-1,y,dist+kor(mat[y][x],'W')});
        }
        if (x<m-1){
            dijklis.push({x+1,y,dist+kor(mat[y][x],'E')});
        }
    }
    cout << "-1\n";
}

Compilation message

adventure.cpp: In function 'char slje(char)':
adventure.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
   18 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 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 1 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 344 KB Output is correct
2 Correct 1 ms 500 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 428 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 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 1 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 344 KB Output is correct
26 Correct 1 ms 500 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 428 KB Output is correct
30 Correct 1 ms 440 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 9 ms 604 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 11 ms 672 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 116 ms 2076 KB Output is correct
40 Correct 114 ms 1904 KB Output is correct
41 Correct 10 ms 1880 KB Output is correct
42 Correct 108 ms 2028 KB Output is correct
43 Correct 72 ms 15872 KB Output is correct
44 Correct 10 ms 1884 KB Output is correct