結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-11 04:38:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,355 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 114,812 KB
実行使用メモリ 21,756 KB
最終ジャッジ日時 2023-08-31 01:43:03
合計ジャッジ時間 9,416 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 52 ms
5,948 KB
testcase_11 WA -
testcase_12 AC 73 ms
8,952 KB
testcase_13 WA -
testcase_14 AC 60 ms
7,072 KB
testcase_15 WA -
testcase_16 AC 73 ms
7,196 KB
testcase_17 AC 57 ms
14,152 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 63 ms
6,964 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 180 ms
21,504 KB
testcase_30 WA -
testcase_31 AC 181 ms
21,656 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 95 ms
7,980 KB
testcase_35 AC 84 ms
7,600 KB
testcase_36 AC 82 ms
7,204 KB
testcase_37 AC 76 ms
7,480 KB
testcase_38 AC 90 ms
7,400 KB
testcase_39 AC 69 ms
8,084 KB
testcase_40 AC 71 ms
8,196 KB
testcase_41 AC 70 ms
8,160 KB
testcase_42 AC 70 ms
8,092 KB
testcase_43 AC 69 ms
8,076 KB
testcase_44 AC 112 ms
20,164 KB
testcase_45 AC 113 ms
20,092 KB
testcase_46 AC 110 ms
20,184 KB
testcase_47 AC 109 ms
20,176 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;
using ll = long long;

int main(){

    ll N, M, X, Y, ans;
    cin >> N >> M;
    vector<ll> H(N);
    for (int i=0; i<N; i++) cin >> H[i];
    vector<vector<ll>> E(N);

    for (int i=0; i<M; i++){
        cin >> X >> Y; X--; Y--;
        E[X].push_back(Y);
        E[Y].push_back(X);
    }

    vector<vector<ll>> dp(N, vector<ll>(2, -1e18)), dp2(N, vector<ll>(2, -1e18));
    dp[0][0] = 0; dp2[N-1][0] = 0;
    
    for (int i=1; i<N; i++){
        for (auto k : E[i]){
            if (H[k] > H[i] && k < i) dp[i][0] = max({dp[i][0], dp[k][0], dp[k][1]});
            if (H[k] < H[i] && k < i) dp[i][1] = max(dp[i][1], dp[k][0]+H[i]-H[k]);
        }
    }
    ans = max(dp[N-1][0], dp[N-1][1]);
    if (ans == -1e18) ans = -1;
    cout << ans << endl;

    for (int i=N-1; i>=0; i--){
        for (auto k : E[i]){
            if (H[k] > H[i] && k > i) dp2[i][0] = max({dp2[i][0], dp2[k][0], dp2[k][1]});
            if (H[k] < H[i] && k > i) dp2[i][1] = max(dp2[i][1], dp2[k][0]+H[i]-H[k]);
        }
    }
    ans = max(dp2[0][0], dp2[0][1]);
    if (ans < 0) ans = -1;
    cout << ans << endl;

    return 0;
}
0