답안 #454799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
454799 2021-08-05T08:22:13 Z myvaluska Awesome Arrowland Adventure (eJOI19_adventure) C++14
100 / 100
227 ms 39180 KB
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <cmath>
#include <tuple>
#include <queue>
#include <functional>
using namespace std;
/*long long int power(long long int n, int k)
{
    long long int vys = 1;
    for (int i = 0; i < k; i++)
    {
        vys = (vys * (n - i)) / (i + 1);
    }
    return vys;
}*/
const long long int maxn = 100000000000000037;
    int n;
    int m;
    string s;
    int pole[537][537];
    long long vzdial[250037];
    vector<vector<int>>v(250037);
    vector<vector<int>>w(250037);
    vector<bool>navst(250037);
    void dijkstrovalgoritmus()
    {
        for (int i = 0; i < n * m; i++)
        {
vzdial[i] = -maxn;
        }
            
        vzdial[0] = 0;
        for (int i = 0; i < n * m; i++)
        {
            navst[i] = false;
        }

        priority_queue<pair<int, int>> q;
        q.push({ 0, 0 });
        while (!q.empty())
        {
            int t = -q.top().first; 
            int u = q.top().second; q.pop();
            if (navst[u])
            {
                continue;
            }
            vzdial[u] = t;
            navst[u] = true;
            for (int i = 0; i < v[u].size(); i++)
            {
                q.push({ -t - w[u][i], v[u][i] });
            }
        }
    }
    int vzdialednost(int x, int y)
    {
        int vys = y + 4 - x;
        return vys%4;
    }
int main()
{
    /*for (int i = 0; i < 10; i++)
    {
        std::cout << "Hello Flash!\n";
    }*/
    cin >> n;
    cin >> m;

    for (int i = 0; i < n; i++)
    {
        cin >> s;
        for (int j = 0; j < m; j++)
        {
            if (s[j] == 'N')
            {
                pole[i][j] = 1;
            }
            if (s[j] == 'E')
            {
                pole[i][j] = 2;
            }
            if (s[j] == 'S')
            {
                pole[i][j] = 3;
            }
            if (s[j] == 'W')
            {
                pole[i][j] = 4;
            }
            if (s[j] == 'X')
            {
                pole[i][j] = -1;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (pole[i][j] == -1)
            {

            }
            else
            {
                int poz = i * m + j;
                if (i == 0 && j == 0)
                {
                    v[poz].push_back(i * m + j + 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 2));

                    v[poz].push_back((i + 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 3));
                }
                //////
                else if (i == n - 1 && j == m - 1)
                {
                    v[poz].push_back(i * m + j - 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 4));

                    v[poz].push_back((i - 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 1));
                }
                else if (i == 0 && j == m - 1)
                {
                    v[poz].push_back(i * n + j - 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 4));

                   v[poz].push_back((i + 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 3));
                }
                else if (j == 0 && i == n - 1)
                {
                    v[poz].push_back(i * m + j + 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 2));

                    v[poz].push_back((i - 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 1));
                }
                else if (i == 0)
                {
                    v[poz].push_back(i * m + j + 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 2));

                    v[poz].push_back(i * m + j - 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 4));

                    v[poz].push_back((i + 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 3));
                }
                else if (j == 0)
                {
                    v[poz].push_back(i * m + j + 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 2));

                    v[poz].push_back((i - 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 1));

                    v[poz].push_back((i + 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 3));
                }
                else if (i == n - 1)
                {
                    v[poz].push_back(i * m + j + 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 2));

                    v[poz].push_back(i * m + j - 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 4));

                    v[poz].push_back((i - 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 1));
                }
                else if (j == m - 1)
                {
                    v[poz].push_back(i * m + j - 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 4));

                    v[poz].push_back((i - 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 1));

                    v[poz].push_back((i + 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 3));
                }
                else
                {
                    v[poz].push_back(i * m + j - 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 4));

                    v[poz].push_back(i * m + j + 1);
                    w[poz].push_back(vzdialednost(pole[i][j], 2));

                    v[poz].push_back((i - 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 1));

                    v[poz].push_back((i + 1) * m + j);
                    w[poz].push_back(vzdialednost(pole[i][j], 3));
                }
            }
        }
    }
    dijkstrovalgoritmus();
    if (vzdial[n * m - 1] == -maxn)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << vzdial[n * m - 1] << endl;
    }
    //cout << "TU" << endl;
    return 0;
}

Compilation message

adventure.cpp: In function 'void dijkstrovalgoritmus()':
adventure.cpp:53:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             for (int i = 0; i < v[u].size(); i++)
      |                             ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 7 ms 12108 KB Output is correct
3 Correct 7 ms 12092 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 7 ms 12108 KB Output is correct
6 Correct 7 ms 12128 KB Output is correct
7 Correct 7 ms 11980 KB Output is correct
8 Correct 7 ms 12108 KB Output is correct
9 Correct 7 ms 12108 KB Output is correct
10 Correct 7 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 7 ms 12108 KB Output is correct
3 Correct 7 ms 12092 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 7 ms 12108 KB Output is correct
6 Correct 7 ms 12128 KB Output is correct
7 Correct 7 ms 11980 KB Output is correct
8 Correct 7 ms 12108 KB Output is correct
9 Correct 7 ms 12108 KB Output is correct
10 Correct 7 ms 12108 KB Output is correct
11 Correct 7 ms 12092 KB Output is correct
12 Correct 7 ms 12100 KB Output is correct
13 Correct 7 ms 12092 KB Output is correct
14 Correct 7 ms 12048 KB Output is correct
15 Correct 7 ms 12088 KB Output is correct
16 Correct 8 ms 12136 KB Output is correct
17 Correct 9 ms 12096 KB Output is correct
18 Correct 8 ms 12108 KB Output is correct
19 Correct 7 ms 12092 KB Output is correct
20 Correct 9 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 7 ms 12108 KB Output is correct
3 Correct 7 ms 12108 KB Output is correct
4 Correct 7 ms 12088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 7 ms 12108 KB Output is correct
3 Correct 7 ms 12108 KB Output is correct
4 Correct 7 ms 12108 KB Output is correct
5 Correct 8 ms 12108 KB Output is correct
6 Correct 8 ms 12092 KB Output is correct
7 Correct 7 ms 12096 KB Output is correct
8 Correct 7 ms 12092 KB Output is correct
9 Correct 7 ms 12108 KB Output is correct
10 Correct 8 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 7 ms 12108 KB Output is correct
3 Correct 7 ms 12092 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 7 ms 12108 KB Output is correct
6 Correct 7 ms 12128 KB Output is correct
7 Correct 7 ms 11980 KB Output is correct
8 Correct 7 ms 12108 KB Output is correct
9 Correct 7 ms 12108 KB Output is correct
10 Correct 7 ms 12108 KB Output is correct
11 Correct 7 ms 12092 KB Output is correct
12 Correct 7 ms 12100 KB Output is correct
13 Correct 7 ms 12092 KB Output is correct
14 Correct 7 ms 12048 KB Output is correct
15 Correct 7 ms 12088 KB Output is correct
16 Correct 8 ms 12136 KB Output is correct
17 Correct 9 ms 12096 KB Output is correct
18 Correct 8 ms 12108 KB Output is correct
19 Correct 7 ms 12092 KB Output is correct
20 Correct 9 ms 12108 KB Output is correct
21 Correct 7 ms 12108 KB Output is correct
22 Correct 7 ms 12108 KB Output is correct
23 Correct 7 ms 12108 KB Output is correct
24 Correct 7 ms 12088 KB Output is correct
25 Correct 7 ms 12108 KB Output is correct
26 Correct 7 ms 12108 KB Output is correct
27 Correct 7 ms 12108 KB Output is correct
28 Correct 7 ms 12108 KB Output is correct
29 Correct 8 ms 12108 KB Output is correct
30 Correct 8 ms 12092 KB Output is correct
31 Correct 7 ms 12096 KB Output is correct
32 Correct 7 ms 12092 KB Output is correct
33 Correct 7 ms 12108 KB Output is correct
34 Correct 8 ms 12108 KB Output is correct
35 Correct 23 ms 13564 KB Output is correct
36 Correct 8 ms 12236 KB Output is correct
37 Correct 25 ms 13900 KB Output is correct
38 Correct 19 ms 15024 KB Output is correct
39 Correct 191 ms 27872 KB Output is correct
40 Correct 199 ms 27904 KB Output is correct
41 Correct 74 ms 27844 KB Output is correct
42 Correct 200 ms 27912 KB Output is correct
43 Correct 227 ms 39180 KB Output is correct
44 Correct 73 ms 27844 KB Output is correct