Submission #288530

# Submission time Handle Problem Language Result Execution time Memory
288530 2020-09-01T15:18:36 Z FulopMate Awesome Arrowland Adventure (eJOI19_adventure) C++14
100 / 100
192 ms 31276 KB
#include <bits/stdc++.h>

using namespace std;
vector<int> g[250000], s[250000];
char mp[500][500];
int tav[250000];

unordered_map<char, array<int, 4>> dirtos = {
    {'E', {0, 1, 2, 3}},
    {'S', {3, 0, 1, 2}},
    {'W', {2, 3, 0, 1}},
    {'N', {1, 2, 3, 0}}
};

int main(){
    int n, m; cin>>n>>m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            char c; cin>>c;
            mp[i][j] = c;
            if(c=='X')continue;
            int nodeindex = i*500+j;
            if(j < m-1 && mp[i][j+1] != 'X'){
                g[nodeindex].push_back(nodeindex+1);
                s[nodeindex].push_back(dirtos[c][0]);
            }
            if(i < n-1 && mp[i+1][j] != 'X'){
                g[nodeindex].push_back(nodeindex+500);
                s[nodeindex].push_back(dirtos[c][1]);
            }
            if(j > 0 && mp[i][j-1] != 'X'){
                g[nodeindex].push_back(nodeindex-1);
                s[nodeindex].push_back(dirtos[c][2]);
            }
            if(i > 0 && mp[i-1][j] != 'X'){
                g[nodeindex].push_back(nodeindex-500);
                s[nodeindex].push_back(dirtos[c][3]);
            }
        }
    }
    priority_queue<pair<int,int>> q;
    for(int&i:tav)i=INT_MAX;
    tav[0] = 0;
    q.push({0, 0});
    while(!q.empty()){
        int v = q.top().second;
        int t = -q.top().first;
        q.pop();
        if(tav[v] < t)continue;
        for(int i = 0; i < g[v].size(); i++){
            int k = g[v][i];
            int su = s[v][i];
            if(t + su < tav[k]){
                tav[k] = t+su;
                q.push({-tav[k], k});
            }
        }
    }
    if(tav[(n-1)*500+(m-1)] == INT_MAX)cout<<-1;
    else cout<<tav[(n-1)*500+(m-1)];
    return 0;
}

Compilation message

adventure.cpp: In function 'int main()':
adventure.cpp:50:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int i = 0; i < g[v].size(); i++){
      |                        ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 13056 KB Output is correct
2 Correct 9 ms 13056 KB Output is correct
3 Correct 9 ms 13056 KB Output is correct
4 Correct 9 ms 13056 KB Output is correct
5 Correct 9 ms 13056 KB Output is correct
6 Correct 9 ms 13056 KB Output is correct
7 Correct 9 ms 13092 KB Output is correct
8 Correct 9 ms 13056 KB Output is correct
9 Correct 9 ms 13056 KB Output is correct
10 Correct 9 ms 13056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 13056 KB Output is correct
2 Correct 9 ms 13056 KB Output is correct
3 Correct 9 ms 13056 KB Output is correct
4 Correct 9 ms 13056 KB Output is correct
5 Correct 9 ms 13056 KB Output is correct
6 Correct 9 ms 13056 KB Output is correct
7 Correct 9 ms 13092 KB Output is correct
8 Correct 9 ms 13056 KB Output is correct
9 Correct 9 ms 13056 KB Output is correct
10 Correct 9 ms 13056 KB Output is correct
11 Correct 9 ms 13056 KB Output is correct
12 Correct 9 ms 13056 KB Output is correct
13 Correct 9 ms 13056 KB Output is correct
14 Correct 9 ms 13056 KB Output is correct
15 Correct 9 ms 13056 KB Output is correct
16 Correct 9 ms 13056 KB Output is correct
17 Correct 9 ms 13056 KB Output is correct
18 Correct 9 ms 13056 KB Output is correct
19 Correct 9 ms 13056 KB Output is correct
20 Correct 9 ms 13056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13056 KB Output is correct
2 Correct 9 ms 13056 KB Output is correct
3 Correct 10 ms 13056 KB Output is correct
4 Correct 9 ms 13056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13056 KB Output is correct
2 Correct 9 ms 13056 KB Output is correct
3 Correct 9 ms 13056 KB Output is correct
4 Correct 9 ms 13056 KB Output is correct
5 Correct 10 ms 13056 KB Output is correct
6 Correct 10 ms 13056 KB Output is correct
7 Correct 9 ms 13056 KB Output is correct
8 Correct 9 ms 13056 KB Output is correct
9 Correct 9 ms 13056 KB Output is correct
10 Correct 9 ms 13056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 13056 KB Output is correct
2 Correct 9 ms 13056 KB Output is correct
3 Correct 9 ms 13056 KB Output is correct
4 Correct 9 ms 13056 KB Output is correct
5 Correct 9 ms 13056 KB Output is correct
6 Correct 9 ms 13056 KB Output is correct
7 Correct 9 ms 13092 KB Output is correct
8 Correct 9 ms 13056 KB Output is correct
9 Correct 9 ms 13056 KB Output is correct
10 Correct 9 ms 13056 KB Output is correct
11 Correct 9 ms 13056 KB Output is correct
12 Correct 9 ms 13056 KB Output is correct
13 Correct 9 ms 13056 KB Output is correct
14 Correct 9 ms 13056 KB Output is correct
15 Correct 9 ms 13056 KB Output is correct
16 Correct 9 ms 13056 KB Output is correct
17 Correct 9 ms 13056 KB Output is correct
18 Correct 9 ms 13056 KB Output is correct
19 Correct 9 ms 13056 KB Output is correct
20 Correct 9 ms 13056 KB Output is correct
21 Correct 9 ms 13056 KB Output is correct
22 Correct 9 ms 13056 KB Output is correct
23 Correct 10 ms 13056 KB Output is correct
24 Correct 9 ms 13056 KB Output is correct
25 Correct 9 ms 13056 KB Output is correct
26 Correct 9 ms 13056 KB Output is correct
27 Correct 9 ms 13056 KB Output is correct
28 Correct 9 ms 13056 KB Output is correct
29 Correct 10 ms 13056 KB Output is correct
30 Correct 10 ms 13056 KB Output is correct
31 Correct 9 ms 13056 KB Output is correct
32 Correct 9 ms 13056 KB Output is correct
33 Correct 9 ms 13056 KB Output is correct
34 Correct 9 ms 13056 KB Output is correct
35 Correct 23 ms 14228 KB Output is correct
36 Correct 10 ms 13184 KB Output is correct
37 Correct 25 ms 14464 KB Output is correct
38 Correct 25 ms 15360 KB Output is correct
39 Correct 152 ms 26104 KB Output is correct
40 Correct 151 ms 26104 KB Output is correct
41 Correct 107 ms 26116 KB Output is correct
42 Correct 154 ms 26104 KB Output is correct
43 Correct 192 ms 31276 KB Output is correct
44 Correct 105 ms 25996 KB Output is correct