結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー Manuel1024Manuel1024
提出日時 2022-12-11 08:35:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 80,924 KB
実行使用メモリ 13,436 KB
最終ジャッジ日時 2024-04-23 06:44:45
合計ジャッジ時間 7,858 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 119 ms
10,176 KB
testcase_05 AC 98 ms
8,392 KB
testcase_06 AC 18 ms
6,940 KB
testcase_07 AC 23 ms
6,940 KB
testcase_08 AC 115 ms
12,196 KB
testcase_09 AC 96 ms
7,804 KB
testcase_10 AC 49 ms
6,944 KB
testcase_11 AC 83 ms
9,156 KB
testcase_12 AC 64 ms
6,940 KB
testcase_13 AC 68 ms
10,256 KB
testcase_14 AC 56 ms
6,940 KB
testcase_15 AC 75 ms
9,856 KB
testcase_16 AC 63 ms
6,940 KB
testcase_17 AC 47 ms
9,032 KB
testcase_18 AC 71 ms
10,344 KB
testcase_19 AC 139 ms
11,928 KB
testcase_20 AC 33 ms
6,944 KB
testcase_21 AC 69 ms
6,940 KB
testcase_22 AC 63 ms
6,940 KB
testcase_23 AC 110 ms
10,652 KB
testcase_24 AC 148 ms
13,296 KB
testcase_25 AC 148 ms
13,420 KB
testcase_26 AC 146 ms
13,300 KB
testcase_27 AC 150 ms
13,432 KB
testcase_28 AC 150 ms
13,300 KB
testcase_29 AC 147 ms
13,304 KB
testcase_30 AC 152 ms
13,436 KB
testcase_31 AC 146 ms
13,428 KB
testcase_32 AC 150 ms
13,300 KB
testcase_33 AC 158 ms
13,292 KB
testcase_34 AC 88 ms
6,944 KB
testcase_35 AC 81 ms
6,940 KB
testcase_36 AC 74 ms
6,944 KB
testcase_37 AC 70 ms
6,940 KB
testcase_38 AC 84 ms
6,940 KB
testcase_39 AC 67 ms
6,940 KB
testcase_40 AC 65 ms
6,944 KB
testcase_41 AC 66 ms
6,944 KB
testcase_42 AC 63 ms
6,940 KB
testcase_43 AC 63 ms
6,944 KB
testcase_44 AC 96 ms
13,000 KB
testcase_45 AC 97 ms
13,004 KB
testcase_46 AC 97 ms
13,128 KB
testcase_47 AC 91 ms
13,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n, m; cin >> n >> m;
    vector<int> h(n);
    for(auto &it: h) cin >> it;
    vector<vector<int>> G(n);
    for(int i = 0; i < m; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        G[x].emplace_back(y);
        G[y].emplace_back(x);
    }

    vector<vector<ll>> dp1(2, vector<ll>(n, -(1LL << 60)));
    dp1[0][0] = 0;
    for(int i = 0; i < n; i++){
        for(auto &nex: G[i]){
            if(nex < i) continue;
            if(h[i] < h[nex]) dp1[1][nex] = max(dp1[1][nex], dp1[0][i]+h[nex]-h[i]);
            else dp1[0][nex] = max(dp1[0][nex], max(dp1[0][i], dp1[1][i]));
        }
    }
    cout << (max(dp1[0][n-1], dp1[1][n-1]) >= 0 ? max(dp1[0][n-1], dp1[1][n-1]) : -1) << endl;
    vector<vector<ll>> dp2(2, vector<ll>(n, -(1LL << 60)));
    dp2[0][n-1] = 0;
    for(int i = n-1; i >= 0; i--){
        for(auto &nex: G[i]){
            if(nex > i) continue;
            if(h[i] < h[nex]) dp2[1][nex] = max(dp2[1][nex], dp2[0][i]+h[nex]-h[i]);
            else dp2[0][nex] = max(dp2[0][nex], max(dp2[0][i], dp2[1][i]));
        }
    }
    cout << (max(dp2[0][0], dp2[1][0]) >= 0 ? max(dp2[0][0], dp2[1][0]) : -1) << endl;
    return 0;
}
0