結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-11 04:08:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,113 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 127,888 KB
実行使用メモリ 31,228 KB
最終ジャッジ日時 2023-08-31 01:42:06
合計ジャッジ時間 9,686 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 160 ms
22,164 KB
testcase_05 AC 123 ms
16,524 KB
testcase_06 AC 25 ms
7,224 KB
testcase_07 AC 31 ms
8,116 KB
testcase_08 AC 160 ms
28,360 KB
testcase_09 AC 116 ms
13,912 KB
testcase_10 WA -
testcase_11 AC 120 ms
19,188 KB
testcase_12 WA -
testcase_13 AC 102 ms
23,096 KB
testcase_14 WA -
testcase_15 AC 107 ms
21,904 KB
testcase_16 WA -
testcase_17 AC 75 ms
20,984 KB
testcase_18 AC 104 ms
23,408 KB
testcase_19 AC 187 ms
27,044 KB
testcase_20 AC 40 ms
9,020 KB
testcase_21 AC 81 ms
12,476 KB
testcase_22 WA -
testcase_23 AC 148 ms
24,072 KB
testcase_24 AC 211 ms
30,932 KB
testcase_25 AC 207 ms
31,040 KB
testcase_26 AC 214 ms
30,936 KB
testcase_27 AC 208 ms
30,872 KB
testcase_28 AC 212 ms
30,932 KB
testcase_29 AC 210 ms
30,920 KB
testcase_30 AC 209 ms
31,068 KB
testcase_31 AC 211 ms
31,228 KB
testcase_32 AC 210 ms
30,868 KB
testcase_33 AC 207 ms
30,984 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 133 ms
29,448 KB
testcase_45 AC 134 ms
29,452 KB
testcase_46 AC 131 ms
29,616 KB
testcase_47 AC 129 ms
29,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;
using ll = long long; 

vector<ll> H;

vector<vector<ll>> dijkstra(vector<vector<ll>> &E, ll start){
 
    ll N = E.size(), t;
    ll from, alt, d;

    pq<tuple<ll, ll, ll>> que;
    vector<vector<ll>> dist(N, vector<ll>(2, 1e18));
    que.push({0, start, 0});
    vector<vector<bool>> visit(N, vector<bool>(2));
    dist[start][0] = 0;
    visit[start][0] = 0;
 
    while(!que.empty()){
        tie(d, from, t) = que.top();
        que.pop();
        if (dist[from][t] < d) continue;
        if (visit[from][t]) continue;
        visit[from][t] = 1;
        for (auto to : E[from]){
            if (start == 0){
                if (to < from) continue;
            } 
            else{
                if (to > from) continue;
            }
            if (H[to]>H[from]){
                if (t == 1) continue;
                alt = d - (H[to]-H[from]);
                if (alt < dist[to][1]){
                    dist[to][1] = alt;
                    que.push({dist[to][1], to, 1});
                }
            }
            else{
                alt = d;
                if (alt < dist[to][0]){
                    dist[to][0] = alt;
                    que.push({dist[to][0], to, 0});
                }
            }
        }
    }
 
    return dist;
}

int main(){

    ll N, M, A, B, C, ans;
    cin >> N >> M;
    H.resize(N);
    for (int i=0; i<N; i++) cin >> H[i];
    vector<vector<ll>> E(N), E2(N);
    for (int i=0; i<M; i++){
        cin >> A >> B;
        A--; B--;
        E[A].push_back(B);
        E[B].push_back(A);
    }
    vector<vector<ll>> dist = dijkstra(E, 0);
    ans = min(dist[N-1][0], dist[N-1][1]);
    cout << (ans == 1e18 ? -1 : -ans) << endl;
    dist = dijkstra(E, N-1);
    ans = min(dist[0][0], dist[0][1]);
    cout << (ans == 1e18 ? -1 : -ans) << endl;
}
0