結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー keisuke6keisuke6
提出日時 2022-10-14 21:39:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 205,516 KB
実行使用メモリ 13,364 KB
最終ジャッジ日時 2023-09-08 20:32:15
合計ジャッジ時間 8,499 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 122 ms
10,696 KB
testcase_05 AC 98 ms
8,776 KB
testcase_06 AC 19 ms
4,640 KB
testcase_07 AC 23 ms
4,912 KB
testcase_08 AC 120 ms
11,720 KB
testcase_09 AC 101 ms
8,292 KB
testcase_10 AC 52 ms
5,800 KB
testcase_11 AC 91 ms
9,256 KB
testcase_12 AC 69 ms
7,152 KB
testcase_13 AC 72 ms
9,192 KB
testcase_14 AC 60 ms
6,432 KB
testcase_15 AC 78 ms
9,384 KB
testcase_16 AC 66 ms
6,664 KB
testcase_17 AC 48 ms
8,132 KB
testcase_18 AC 74 ms
9,348 KB
testcase_19 AC 142 ms
12,356 KB
testcase_20 AC 32 ms
5,148 KB
testcase_21 AC 66 ms
7,068 KB
testcase_22 AC 64 ms
6,552 KB
testcase_23 AC 108 ms
10,756 KB
testcase_24 AC 156 ms
13,284 KB
testcase_25 AC 157 ms
13,280 KB
testcase_26 AC 159 ms
13,364 KB
testcase_27 AC 164 ms
13,260 KB
testcase_28 AC 159 ms
13,308 KB
testcase_29 AC 157 ms
13,260 KB
testcase_30 AC 158 ms
13,292 KB
testcase_31 AC 158 ms
13,288 KB
testcase_32 AC 159 ms
13,296 KB
testcase_33 AC 162 ms
13,308 KB
testcase_34 AC 90 ms
7,808 KB
testcase_35 AC 79 ms
7,628 KB
testcase_36 AC 80 ms
7,276 KB
testcase_37 AC 74 ms
7,408 KB
testcase_38 AC 84 ms
7,260 KB
testcase_39 AC 67 ms
8,160 KB
testcase_40 AC 67 ms
8,152 KB
testcase_41 AC 68 ms
8,000 KB
testcase_42 AC 68 ms
8,084 KB
testcase_43 AC 67 ms
8,016 KB
testcase_44 AC 99 ms
11,744 KB
testcase_45 AC 97 ms
11,748 KB
testcase_46 AC 96 ms
11,724 KB
testcase_47 AC 97 ms
11,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
int f(vector<int> S,vector<vector<int>> &G){
    vector<int> A(N,-1),B(N,-1);
    A[0] = 0;
    for(int i=0;i<N;i++){
        for(int x:G[i]){
            if(x < i) continue;
            if(A[i] != -1){
                if(S[x] < S[i]) A[x] = max(A[x],A[i]);
                else B[x] = max(B[x],A[i]+S[x]-S[i]);
            }
            if(B[i] != -1){
                if(S[x] < S[i]) A[x] = max(A[x],B[i]);
            }
        }
    }
    return max(A[N-1],B[N-1]);
}
int g(vector<int> S,vector<vector<int>> &G){
    vector<int> A(N,-1),B(N,-1);
    A[N-1] = 0;
    for(int i=N-1;i>=0;i--){
        for(int x:G[i]){
            if(x > i) continue;
            if(A[i] != -1){
                if(S[x] < S[i]) A[x] = max(A[x],A[i]);
                else B[x] = max(B[x],A[i]+S[x]-S[i]);
            }
            if(B[i] != -1){
                if(S[x] < S[i]) A[x] = max(A[x],B[i]);
            }
        }
    }
    return max(A[0],B[0]);
}
signed main(){
  int M;
  cin>>N>>M;
  vector<int> S(N);
  for(int i=0;i<N;i++) cin>>S[i];
  vector<vector<int>> G(N);
  for(int i=0;i<M;i++){
      int a,b;
      cin>>a>>b;
      G[a-1].push_back(b-1);
      G[b-1].push_back(a-1);
  }
  cout<<f(S,G)<<endl;cout<<g(S,G)<<endl;
}
0