Submission #988432

# Submission time Handle Problem Language Result Execution time Memory
988432 2024-05-24T17:10:00 Z HasanV11010238 Awesome Arrowland Adventure (eJOI19_adventure) C++17
50 / 100
2000 ms 5676 KB
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
map<char, vector<vector<int>>> dir;
int n, m;
bool check(int x, int y){
    if (x >= 0 && x < n && y >= 0 && y < m){
        return true;
    }
    return false;
}
void init(){
    dir['N'] = {{0, -1, 0},{1, 0, 1}, {0, 1, 2}, {-1, 0, 3}};
    dir['E'] = {{0, -1, 3},{1, 0, 0}, {0, 1, 1}, {-1, 0, 2}};
    dir['S'] = {{0, -1, 2},{1, 0, 3}, {0, 1, 0}, {-1, 0, 1}};
    dir['W'] = {{0, -1, 1},{1, 0, 2}, {0, 1, 3}, {-1, 0, 0}};
    dir['X'] = {};
}
int bfs(vector<vector<char>> ma, vector<vector<int>> costs){
    queue<vector<int>> q;
    q.push({0, 0});
    costs[0][0] = 0;
    vector<vector<int>> us(m, vector<int>(n, 0));
    while(!q.empty()){
        vector<int> u = q.front();
        q.pop();
        vector<vector<int>> moves = dir[ma[u[1]][u[0]]];
        for (auto el : moves){
            int x = el[0] + u[0], y = el[1] + u[1];
            if (check(x, y) && costs[y][x] > costs[u[1]][u[0]] + el[2]){
                costs[y][x] = costs[u[1]][u[0]] + el[2];
                if (us[y][x] == 0){
                    q.push({x, y});
                }
                us[y][x];
            }
        }
    }
    return costs[m - 1][n - 1];
}
int main(){
    cin>>m>>n;
    vector<vector<char>> ma;
    vector<vector<int>> costs;
    char r;
    for (int i = 0; i < m; i++){
        ma.push_back({});
        costs.push_back({});
        for (int j = 0; j < n; j++){
            cin>>r;
            ma[i].push_back(r);
            costs[i].push_back(INF);
        }
    }
    init();
    int res = bfs(ma, costs);
    if (res == INF){
        cout<<-1;
    }
    else{
        cout<<res;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 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
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 432 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 692 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 428 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 1 ms 432 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 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
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 432 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 692 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 428 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 1 ms 432 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 186 ms 860 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 111 ms 860 KB Output is correct
38 Correct 3 ms 1368 KB Output is correct
39 Execution timed out 2070 ms 5676 KB Time limit exceeded
40 Halted 0 ms 0 KB -