답안 #999823

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999823 2024-06-16T07:19:25 Z LilPluton Awesome Arrowland Adventure (eJOI19_adventure) C++14
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
// author : Pluton
#define OPT         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int         ll
#define ll          long long
#define pb          push_back
#define arr         array
#define fi          first
#define se          second
#define rep(i,j,k)  for(int i = j; i <= k; ++i)
#define all(a)      a.begin(),a.end()
#define pii         pair<int,int>
using namespace std;
const int INF = 1e18;

struct BIT
{
    int n;
    vector<int> ft;
    void init(int N)
    {
        n = N + 5;
        ft.assign(n + 5, 0);
    }
    void add(int pos, int val)
    {
        for (pos = pos + 1; pos <= n; pos += pos & -pos) ft[pos] += val;
    }
    int get(int pos, int res = 0)
    {
        for (pos = pos + 1; pos > 0; pos -= pos & -pos) res += ft[pos];
        return res;
    }
};

map<char,vector<vector<int>>>d;
int n, m;
bool f(int x,int y)
{
    if(x >= 0 && x <= n && y >= 0 && y <= m)
        return true;
    return false;
}
const int N = 505;
vector<vector<char>>g(N);
vector<vector<int>>cost(N);


void _()
{
    d['N'] = {{0, -1, 0},{1, 0, 1}, {0, 1, 2}, {-1, 0, 3}};
    d['E'] = {{0, -1, 3},{1, 0, 0}, {0, 1, 1}, {-1, 0, 2}};
    d['S'] = {{0, -1, 2},{1, 0, 3}, {0, 1, 0}, {-1, 0, 1}};
    d['W'] = {{0, -1, 1},{1, 0, 2}, {0, 1, 3}, {-1, 0, 0}};
    d['X'] = {};
    cin >> m >> n;
    for(int i = 0; i < m; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            char c;
            cin >> c;
            g[i].push_back(c);
            cost[i].push_back(INF);
        }
    }
    priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>>q;
    q.push({0,0,0});
    cost[0][0] = 0;
    vector<vector<int>>vis(m,vector<int>(n,0));
    while(!q.empty())
    {
        vector<int>u = q.top();
        q.pop();
        auto move = d[g[u[2]][u[1]]];
        for(auto e : move)
        {
            int x = e[0] + u[1];
            int y = e[1] + u[2];
            if(f(x, y) && cost[y][x] > cost[u[2]][u[1]] + e[2])
            {
                cost[y][x] = cost[u[2]][u[1]] + e[2];
                if (vis[y][x] == 0){
                    q.push({cost[y][x], x, y});
                }
                vis[y][x] = 1;

            }
        }
    }
    cout << (cost[m - 1][n - 1] == INF ? -1 : cost[m - 1][n - 1]);
}

signed main()
{
    OPT
    int tc = 1;
    while(tc--)
    {
        _();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 0 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -