답안 #1042314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1042314 2024-08-02T20:36:25 Z jnjwnwnw Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
230 ms 45036 KB
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define ll long long
#define fff(i,a,b) for(ll i = a; i < b; i++)


ll n, m;
vector<ll> adj[501][501];
ll dir[501][501];
ll table[257];
priority_queue<pair<ll, pair<ll, ll>>> q;
set<pair<ll, ll>> seen;
pair<ll, ll> adjPos[]{{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

int main(){
    // setIO("testing");
    // opposite of input, for my own clarity
    cin >> n >> m;
    // NESW, so if i have W and want to know how many i need to do to get N it should be 
    table['N'] = 0;
    table['E'] = 1;
    table['S'] = 2;
    table['W'] = 3;
    table['X'] = -1;
    fff(i, 0, n){
        fff(j, 0, m){
            char c; cin >> c;
            dir[i][j] = table[c];
        }
    }

    q.push({0, {0, 0}});

    while (q.size()){
        auto [d, pos] = q.top(); q.pop();
        auto [y, x] = pos;
        if (seen.find({y, x}) != seen.end()) continue;
        // process this spot. 
        seen.insert({y, x});
        if (y == n-1 && x == m-1){
            // at the end, output dist
            cout << -d << endl;
            return 0;
        }
        // now, move to nearby, if can
        if (dir[y][x] == -1) continue;
        fff(i, 0, 4){
            auto [dy, dx] = adjPos[i];
            ll ny = y+dy, nx = x+dx;
            if (ny < 0 || ny >= n || nx < 0 || nx >= m) continue;
            auto cost = -((i - dir[y][x]+4)%4);
            q.push({cost+d, {ny, nx}});
        }
    }
    cout << -1 << endl;
}

Compilation message

adventure.cpp: In function 'int main()':
adventure.cpp:38:31: warning: array subscript has type 'char' [-Wchar-subscripts]
   38 |             dir[i][j] = table[c];
      |                               ^
adventure.cpp: In function 'void setIO(std::string)':
adventure.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
adventure.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 1 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 1 ms 8028 KB Output is correct
5 Correct 1 ms 8028 KB Output is correct
6 Correct 1 ms 8028 KB Output is correct
7 Correct 1 ms 8028 KB Output is correct
8 Correct 1 ms 8028 KB Output is correct
9 Correct 1 ms 8028 KB Output is correct
10 Correct 2 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 1 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 1 ms 8028 KB Output is correct
5 Correct 1 ms 8028 KB Output is correct
6 Correct 1 ms 8028 KB Output is correct
7 Correct 1 ms 8028 KB Output is correct
8 Correct 1 ms 8028 KB Output is correct
9 Correct 1 ms 8028 KB Output is correct
10 Correct 2 ms 8028 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 1 ms 8028 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
15 Correct 2 ms 8132 KB Output is correct
16 Correct 2 ms 8028 KB Output is correct
17 Correct 2 ms 8028 KB Output is correct
18 Correct 2 ms 8028 KB Output is correct
19 Correct 2 ms 8028 KB Output is correct
20 Correct 2 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8052 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8032 KB Output is correct
6 Correct 3 ms 8028 KB Output is correct
7 Correct 2 ms 8028 KB Output is correct
8 Correct 1 ms 8028 KB Output is correct
9 Correct 1 ms 8028 KB Output is correct
10 Correct 2 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 1 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 1 ms 8028 KB Output is correct
5 Correct 1 ms 8028 KB Output is correct
6 Correct 1 ms 8028 KB Output is correct
7 Correct 1 ms 8028 KB Output is correct
8 Correct 1 ms 8028 KB Output is correct
9 Correct 1 ms 8028 KB Output is correct
10 Correct 2 ms 8028 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 1 ms 8028 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
15 Correct 2 ms 8132 KB Output is correct
16 Correct 2 ms 8028 KB Output is correct
17 Correct 2 ms 8028 KB Output is correct
18 Correct 2 ms 8028 KB Output is correct
19 Correct 2 ms 8028 KB Output is correct
20 Correct 2 ms 8028 KB Output is correct
21 Correct 2 ms 8028 KB Output is correct
22 Correct 2 ms 8028 KB Output is correct
23 Correct 2 ms 8052 KB Output is correct
24 Correct 2 ms 8028 KB Output is correct
25 Correct 2 ms 8024 KB Output is correct
26 Correct 2 ms 8028 KB Output is correct
27 Correct 2 ms 8028 KB Output is correct
28 Correct 2 ms 8028 KB Output is correct
29 Correct 2 ms 8032 KB Output is correct
30 Correct 3 ms 8028 KB Output is correct
31 Correct 2 ms 8028 KB Output is correct
32 Correct 1 ms 8028 KB Output is correct
33 Correct 1 ms 8028 KB Output is correct
34 Correct 2 ms 8028 KB Output is correct
35 Correct 22 ms 9564 KB Output is correct
36 Correct 2 ms 8028 KB Output is correct
37 Correct 19 ms 9820 KB Output is correct
38 Correct 2 ms 8284 KB Output is correct
39 Correct 200 ms 24020 KB Output is correct
40 Correct 223 ms 24144 KB Output is correct
41 Correct 8 ms 8540 KB Output is correct
42 Correct 230 ms 24064 KB Output is correct
43 Correct 94 ms 45036 KB Output is correct
44 Correct 7 ms 8540 KB Output is correct