답안 #454786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
454786 2021-08-05T08:17:41 Z myvaluska Awesome Arrowland Adventure (eJOI19_adventure) C++14
12 / 100
10 ms 13112 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 >> m;
    cin >> n;
    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 Incorrect 8 ms 12748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 12748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 8 ms 12040 KB Output is correct
3 Correct 7 ms 12108 KB Output is correct
4 Correct 10 ms 12096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 13112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 12748 KB Output isn't correct
2 Halted 0 ms 0 KB -