結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー hourenhouren
提出日時 2022-10-14 21:49:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,599 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 174,120 KB
実行使用メモリ 13,508 KB
最終ジャッジ日時 2023-09-08 20:48:56
合計ジャッジ時間 6,269 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 63 ms
10,512 KB
testcase_05 AC 50 ms
8,712 KB
testcase_06 AC 9 ms
4,612 KB
testcase_07 AC 12 ms
5,048 KB
testcase_08 AC 60 ms
12,468 KB
testcase_09 AC 47 ms
7,268 KB
testcase_10 AC 23 ms
4,776 KB
testcase_11 AC 46 ms
9,152 KB
testcase_12 AC 34 ms
6,368 KB
testcase_13 AC 36 ms
10,196 KB
testcase_14 AC 29 ms
5,560 KB
testcase_15 AC 39 ms
10,048 KB
testcase_16 AC 31 ms
5,556 KB
testcase_17 AC 23 ms
9,136 KB
testcase_18 AC 37 ms
10,440 KB
testcase_19 AC 72 ms
12,048 KB
testcase_20 AC 16 ms
5,192 KB
testcase_21 AC 34 ms
6,676 KB
testcase_22 AC 30 ms
5,592 KB
testcase_23 AC 56 ms
10,716 KB
testcase_24 AC 79 ms
13,400 KB
testcase_25 AC 79 ms
13,500 KB
testcase_26 AC 87 ms
13,344 KB
testcase_27 AC 86 ms
13,352 KB
testcase_28 AC 83 ms
13,508 KB
testcase_29 AC 85 ms
13,492 KB
testcase_30 AC 84 ms
13,348 KB
testcase_31 AC 85 ms
13,352 KB
testcase_32 AC 83 ms
13,360 KB
testcase_33 AC 79 ms
13,472 KB
testcase_34 AC 40 ms
6,024 KB
testcase_35 AC 36 ms
5,460 KB
testcase_36 AC 35 ms
5,368 KB
testcase_37 AC 33 ms
5,568 KB
testcase_38 AC 37 ms
5,560 KB
testcase_39 AC 29 ms
5,676 KB
testcase_40 AC 29 ms
5,836 KB
testcase_41 AC 29 ms
5,812 KB
testcase_42 AC 28 ms
5,780 KB
testcase_43 AC 29 ms
5,696 KB
testcase_44 AC 43 ms
13,184 KB
testcase_45 AC 42 ms
13,128 KB
testcase_46 AC 44 ms
13,168 KB
testcase_47 AC 43 ms
13,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
const ll INF = (1LL<<60);
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    vector<vector<int>> to(n);
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--; y--;
        to[x].push_back(y);
        to[y].push_back(x);
    }
    vector<vector<ll>> dp(2,vector<ll>(n,-INF)), dp2(2,vector<ll>(n,-INF));
    dp[0][0] = dp[1][0] = dp2[0][n-1] = dp2[1][n-1] = 0;
    rep(i,n){
        for(int x:to[i]){
            if(i<x){
                if(h[i]<h[x]) chmax(dp[1][x], dp[0][i]+h[x]-h[i]);
                else{
                    chmax(dp[0][x], dp[1][i]);
                    chmax(dp[0][x], dp[0][i]);
                }
            }
        }
    }
    for(int i=n-1;i>=0;i--){
        for(int x:to[i]){
            if(i>x){
                if(h[i]<h[x]) chmax(dp2[1][x], dp2[0][i]+h[x]-h[i]);
                else{
                    chmax(dp2[0][x], dp2[1][i]);
                    chmax(dp2[0][x], dp2[0][i]);
                }
            }
        }
    }
    cout << max<ll>({-1,dp[0][n-1],dp[1][n-1]}) << "\n" << max<ll>({-1,dp2[0][0],dp2[1][0]}) << '\n';
    return 0;
}
0