답안 #999847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999847 2024-06-16T07:33:57 Z LilPluton Awesome Arrowland Adventure (eJOI19_adventure) C++14
34 / 100
1 ms 600 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 >= m || x < 0 || y >= n || y < 0)
        return false;
    return true;
}
const int N = 1000;
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(y, x) && 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 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 360 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Incorrect 0 ms 348 KB Output isn't correct
28 Halted 0 ms 0 KB -