結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー umimelumimel
提出日時 2022-10-14 22:26:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,653 bytes
コンパイル時間 2,061 ms
コンパイル使用メモリ 186,052 KB
実行使用メモリ 35,908 KB
最終ジャッジ日時 2023-09-08 22:34:56
合計ジャッジ時間 9,441 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 143 ms
24,852 KB
testcase_05 AC 113 ms
18,836 KB
testcase_06 AC 24 ms
8,072 KB
testcase_07 AC 29 ms
9,140 KB
testcase_08 AC 155 ms
32,804 KB
testcase_09 AC 114 ms
15,356 KB
testcase_10 WA -
testcase_11 AC 112 ms
21,724 KB
testcase_12 AC 77 ms
12,228 KB
testcase_13 AC 98 ms
26,500 KB
testcase_14 WA -
testcase_15 AC 104 ms
25,148 KB
testcase_16 WA -
testcase_17 AC 71 ms
24,360 KB
testcase_18 AC 99 ms
26,748 KB
testcase_19 AC 171 ms
30,872 KB
testcase_20 AC 38 ms
9,936 KB
testcase_21 AC 78 ms
13,892 KB
testcase_22 WA -
testcase_23 AC 136 ms
27,432 KB
testcase_24 AC 195 ms
35,544 KB
testcase_25 AC 199 ms
35,864 KB
testcase_26 AC 188 ms
35,908 KB
testcase_27 AC 199 ms
35,592 KB
testcase_28 AC 197 ms
35,580 KB
testcase_29 AC 207 ms
35,592 KB
testcase_30 AC 191 ms
35,548 KB
testcase_31 AC 185 ms
35,716 KB
testcase_32 AC 202 ms
35,644 KB
testcase_33 AC 198 ms
35,644 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 132 ms
34,136 KB
testcase_45 AC 132 ms
34,276 KB
testcase_46 AC 128 ms
34,332 KB
testcase_47 AC 127 ms
34,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

int main(){
    ll n, m;
    cin >> n >> m;

    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    vector<vector<ll>> G(n);
    rep(i, m){
        ll u, v;
        cin >> u >> v;
        u--; v--;
        G[u].pb(v);
        G[v].pb(u);
    }

    // cherry
    vector<vector<ll>> cost1(n, vector<ll>(2, -INF));
    vector<vector<bool>> check1(n, vector<bool>(2, false));
    cost1[0][0] = 0;
    priority_queue<tuple<ll, ll, ll>> PQ1;
    PQ1.push({0, 0, 0});
    while(!PQ1.empty()){
        ll u = get<1>(PQ1.top());
        ll isUp = get<2>(PQ1.top());
        PQ1.pop();
        if(check1[u][isUp]) continue;
        check1[u][isUp] = true;

        for(ll v : G[u]){
            if(v < u) continue;
            if(isUp == 0){
                if(h[u] < h[v]){
                    if(cost1[v][1] < cost1[u][0]+(h[v]-h[u])){
                        cost1[v][1] = cost1[u][0]+(h[v]-h[u]);
                        PQ1.push({cost1[v][1], v, 1});
                    }
                }else{
                    if(cost1[v][0] < cost1[u][0]){
                        cost1[v][0] = cost1[u][0];
                        PQ1.push({cost1[v][0], v, 0});
                    }
                }
            }else{
                if(h[u] < h[v]){
                    if(cost1[v][1] < cost1[u][1]+(h[v]-h[u])){
                        
                    }
                }else{
                    if(cost1[v][0] < cost1[u][1]){
                        cost1[v][0] = cost1[u][1];
                        PQ1.push({cost1[v][0], v, 0});
                    }
                }
            }
        }
    }

    // zerukoba
    vector<vector<ll>> cost2(n, vector<ll>(2, -INF));
    vector<vector<bool>> check2(n, vector<bool>(2, false));
    cost2[n-1][0] = 0;
    priority_queue<tuple<ll, ll, ll>> PQ2;
    PQ2.push({0, n-1, 0});
    while(!PQ2.empty()){
        ll u = get<1>(PQ2.top());
        ll isUp = get<2>(PQ2.top());
        PQ2.pop();
        if(check2[u][isUp]) continue;
        check2[u][isUp] = true;

        for(ll v : G[u]){
            if(u < v) continue;
            if(isUp == 0){
                if(h[u] < h[v]){
                    if(cost2[v][1] < cost2[u][0]+(h[v]-h[u])){
                        cost2[v][1] = cost2[u][0]+(h[v]-h[u]);
                        PQ2.push({cost2[v][1], v, 1});
                    }
                }else{
                    if(cost2[v][0] < cost2[u][0]){
                        cost2[v][0] = cost2[u][0];
                        PQ2.push({cost2[v][0], v, 0});
                    }
                }
            }else{
                if(h[u] < h[v]){
                    if(cost2[v][1] < cost2[u][1]+(h[v]-h[u])){
                        
                    }
                }else{
                    if(cost2[v][0] < cost2[u][1]){
                        cost2[v][0] = cost2[u][1];
                        PQ2.push({cost2[v][0], v, 0});
                    }
                }
            }
        }
    }

    ll che=-INF, zer=-INF;
    che = max(cost1[n-1][0], cost1[n-1][1]);
    zer = max(cost2[0][0], cost2[0][1]);

    if(che == -INF){
        cout << -1 << endl;
    }else{
        cout << che << endl;
    }

    if(zer == -INF){
        cout << -1 << endl;
    }else{
        cout << zer << endl;
    }
}
0