結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 55 ms
5,948 KB
testcase_11 WA -
testcase_12 AC 82 ms
8,912 KB
testcase_13 WA -
testcase_14 AC 69 ms
7,004 KB
testcase_15 WA -
testcase_16 AC 75 ms
7,256 KB
testcase_17 AC 62 ms
14,072 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 73 ms
6,948 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 101 ms
8,192 KB
testcase_35 AC 86 ms
7,744 KB
testcase_36 AC 84 ms
7,192 KB
testcase_37 AC 78 ms
7,516 KB
testcase_38 AC 93 ms
7,440 KB
testcase_39 AC 70 ms
8,268 KB
testcase_40 AC 71 ms
8,124 KB
testcase_41 AC 70 ms
8,184 KB
testcase_42 AC 70 ms
8,092 KB
testcase_43 AC 70 ms
8,156 KB
testcase_44 AC 112 ms
20,200 KB
testcase_45 AC 111 ms
20,132 KB
testcase_46 AC 109 ms
20,400 KB
testcase_47 AC 109 ms
20,428 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 == -1e18) ans = -1;
    cout << ans << endl;

    return 0;
}
0