結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー twooimp2twooimp2
提出日時 2024-03-06 21:33:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 5,818 ms
コンパイル使用メモリ 304,936 KB
実行使用メモリ 21,968 KB
最終ジャッジ日時 2024-03-06 21:34:03
合計ジャッジ時間 10,312 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 67 ms
16,128 KB
testcase_05 AC 50 ms
12,800 KB
testcase_06 AC 11 ms
6,676 KB
testcase_07 AC 13 ms
6,784 KB
testcase_08 AC 68 ms
19,968 KB
testcase_09 AC 48 ms
11,136 KB
testcase_10 AC 21 ms
6,676 KB
testcase_11 AC 47 ms
14,080 KB
testcase_12 AC 34 ms
9,088 KB
testcase_13 AC 39 ms
16,128 KB
testcase_14 AC 27 ms
7,296 KB
testcase_15 AC 42 ms
15,488 KB
testcase_16 AC 36 ms
7,552 KB
testcase_17 AC 30 ms
14,464 KB
testcase_18 AC 42 ms
16,256 KB
testcase_19 AC 81 ms
19,456 KB
testcase_20 AC 19 ms
7,296 KB
testcase_21 AC 35 ms
9,856 KB
testcase_22 AC 29 ms
7,424 KB
testcase_23 AC 59 ms
17,280 KB
testcase_24 AC 86 ms
21,960 KB
testcase_25 AC 87 ms
21,960 KB
testcase_26 AC 85 ms
21,964 KB
testcase_27 AC 86 ms
21,968 KB
testcase_28 AC 87 ms
21,968 KB
testcase_29 AC 89 ms
21,968 KB
testcase_30 AC 88 ms
21,964 KB
testcase_31 AC 109 ms
21,964 KB
testcase_32 AC 85 ms
21,964 KB
testcase_33 AC 86 ms
21,964 KB
testcase_34 AC 35 ms
8,320 KB
testcase_35 AC 31 ms
7,680 KB
testcase_36 AC 35 ms
7,168 KB
testcase_37 AC 29 ms
7,552 KB
testcase_38 AC 34 ms
7,680 KB
testcase_39 AC 26 ms
8,320 KB
testcase_40 AC 27 ms
8,320 KB
testcase_41 AC 26 ms
8,320 KB
testcase_42 AC 28 ms
8,192 KB
testcase_43 AC 27 ms
8,320 KB
testcase_44 AC 49 ms
20,552 KB
testcase_45 AC 48 ms
20,552 KB
testcase_46 AC 50 ms
20,552 KB
testcase_47 AC 61 ms
20,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;

void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

int main(){
  IO();
  ll n,m;
  cin>>n>>m;
  vector<ll> h(n);
  for(ll i=0;i<n;i++){
    cin>>h[i];
  }
  vector<vector<ll>> G(n);
  for(ll i=0;i<m;i++){
    ll x,y;
    cin>>x>>y;
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  vector<vector<ll>> dp(n,vector<ll>(2,-1e18));
  dp[0][0]=0;
  for(ll i=0;i<n;i++){
    for(ll j:G[i]){
      if(i<j){
        if(h[i]<h[j]){
          dp[j][1]=max(dp[j][1],dp[i][0]+h[j]-h[i]);
        }else{
          dp[j][0]=max(dp[j][0],max(dp[i][0],dp[i][1]));
        }
      }
    }
  }
  vector<vector<ll>> dp2(n,vector<ll>(2,-1e18));
  dp2[n-1][0]=0;
  for(ll i=n-1;i>=0;i--){
    for(ll j:G[i]){
      if(i>j){
        if(h[i]<h[j]){
          dp2[j][1]=max(dp2[j][1],dp2[i][0]+h[j]-h[i]);
        }else{
          dp2[j][0]=max(dp2[j][0],max(dp2[i][0],dp2[i][1]));
        }
      }
    }
  }
  ll ans1=max(dp[n-1][0],dp[n-1][1]);
  if(ans1<0){
    cout<<-1<<endl;
  }else{
    cout<<ans1<<endl;
  }
  ll ans2=max(dp2[0][0],dp2[0][1]);
  if(ans2<0){
    cout<<-1<<endl;
  }else{
    cout<<ans2<<endl;
  }
}
0