답안 #730374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730374 2023-04-25T18:37:17 Z aykhn Awesome Arrowland Adventure (eJOI19_adventure) C++14
38 / 100
1 ms 324 KB
#include <bits/stdc++.h>

/*
    author: aykhn
    4/24/2023
*/

using namespace std;

typedef long long ll;

#define OPT ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout<<endl;


int main()
{
    OPT;
    int n, m;
    cin >> n >> m;

    vector<vector<char>> v(n, vector<char> (m));
    vector<vector<int>> dist(n, vector<int> (m, inf));

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> v[i][j];
            if (v[i][j] == 'X') dist[i][j] = -inf;
        }
    }

    dist[n - 1][m - 1] = inf;

    priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> pq;

    dist[0][0] = 0;
    pq.push(mpr(0, mpr(0, 0)));

    int a[4] = {-1, 0, 0, 1};
    int b[4] = {0, -1, 1, 0};
    vector<vector<int>> ways(26, vector<int> (26, 0));

    ways[4][18] = 1;
    ways[4][22] = 2;
    ways[4][13] = 3;
    ways[13][4] = 1;
    ways[13][18] = 2;
    ways[13][22] = 3;
    ways[18][22] = 1;
    ways[18][13] = 2;
    ways[18][4] = 3;
    ways[22][13] = 1;
    ways[22][4] = 2;
    ways[22][18] = 3;

    while (!pq.empty())
    {
        int x = pq.top().se.fi;
        int y = pq.top().se.se;
        int w = pq.top().fi;
        pq.pop();

        for (int i = 0; i < 4; i++)
        {
            int x1 = x + a[i];
            int y1 = y + b[i];

            if (x1 >= n || x1 < 0 || y1 >= m || y1 < 0) continue;
            char ch;
            if (a[i] == -1 && b[i] == 0) ch = 'N';
            else if (a[i] == 1 && b[i] == 0) ch = 'S';
            else if (a[i] == 0 && b[i] == -1) ch = 'W';
            else ch = 'E';
            int d = ways[v[x][y] - 'A'][ch - 'A'];
            if (d + w < dist[x1][y1])
            {
                dist[x1][y1] = d + w;
                pq.push(mpr(dist[x1][y1], mpr(x1, y1)));
            }
        }
    }

    cout << (dist[n - 1][m - 1] != inf ? dist[n - 1][m - 1] : -1) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Incorrect 1 ms 212 KB Output isn't correct
25 Halted 0 ms 0 KB -