結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー nystnyst
提出日時 2022-10-14 23:31:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,125 bytes
コンパイル時間 1,205 ms
コンパイル使用メモリ 110,380 KB
実行使用メモリ 12,128 KB
最終ジャッジ日時 2023-09-08 23:58:18
合計ジャッジ時間 7,895 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 116 ms
9,648 KB
testcase_05 AC 93 ms
7,536 KB
testcase_06 AC 18 ms
4,376 KB
testcase_07 AC 22 ms
4,832 KB
testcase_08 AC 121 ms
10,920 KB
testcase_09 AC 90 ms
6,948 KB
testcase_10 WA -
testcase_11 AC 84 ms
8,428 KB
testcase_12 AC 64 ms
5,828 KB
testcase_13 AC 69 ms
9,380 KB
testcase_14 WA -
testcase_15 AC 79 ms
8,896 KB
testcase_16 WA -
testcase_17 AC 48 ms
8,068 KB
testcase_18 AC 73 ms
9,052 KB
testcase_19 AC 141 ms
10,580 KB
testcase_20 AC 30 ms
4,844 KB
testcase_21 AC 63 ms
6,264 KB
testcase_22 AC 62 ms
5,108 KB
testcase_23 AC 103 ms
9,696 KB
testcase_24 AC 150 ms
11,904 KB
testcase_25 AC 148 ms
12,028 KB
testcase_26 AC 150 ms
11,976 KB
testcase_27 AC 149 ms
12,128 KB
testcase_28 AC 146 ms
11,896 KB
testcase_29 AC 147 ms
12,128 KB
testcase_30 AC 148 ms
11,968 KB
testcase_31 AC 149 ms
11,964 KB
testcase_32 AC 148 ms
12,060 KB
testcase_33 AC 150 ms
11,944 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 67 ms
5,812 KB
testcase_40 AC 67 ms
5,620 KB
testcase_41 AC 67 ms
5,676 KB
testcase_42 AC 67 ms
5,788 KB
testcase_43 AC 67 ms
6,076 KB
testcase_44 AC 97 ms
11,860 KB
testcase_45 AC 97 ms
11,708 KB
testcase_46 AC 95 ms
11,756 KB
testcase_47 AC 95 ms
11,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cmath>
#include <bitset>
#include <string>
#include <queue>
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<long long> h(n);
    for(int i=0;i<n;i++) cin >> h[i];
    vector<vector<int>> list(n);

    for(int i=0;i<m;i++){
        int x,y;cin >> x >> y;
        x--;y--;
        list[x].push_back(y);
        list[y].push_back(x);
    }

    vector<vector<long long>> dp(2,vector<long long>(n,-1));
    vector<bool> state(n,false); // その階段にくるときに上がったか
    dp[0][0]=0;
    dp[1][0]=0;
    for(int i =0;i<n;i++){
        for(int j = 0;j<2;j++){
            if(dp[j][i]!=-1){
                for(auto x:list[i]){
                    if(x<i) continue;
                    if(h[i]<h[x] && state[i] == false && dp[0][x] < dp[1][i]+(h[x]-h[i])) {
                        dp[0][x] = dp[1][i]+(h[x]-h[i]);
                        state[x] = true;
                    }else if(h[x]<h[i] && (dp[1][x]<dp[0][i]||dp[1][x]<dp[1][i])){
                        dp[1][x] = max(dp[0][i],dp[1][i]);
                        state[x] = false;
                    }
                }
            }
        }
    }
    cout << max(dp[0][n-1],dp[1][n-1]) << endl;

    dp.clear();
    dp.resize(2);
    dp[0].resize(n,-1);
    dp[1].resize(n,-1);
    state.clear();
    state.resize(n,false);

    dp[0][n-1]=0;
    dp[1][n-1]=0;
    for(int i =n-1;0<=i;i--){
        for(int j = 0;j<2;j++){
            if(dp[j][i]!=-1){
                for(auto x:list[i]){
                    if(i<x) continue;
                    if(h[i]<h[x] && state[i] == false && dp[0][x] < dp[1][i]+(h[x]-h[i])) {
                        dp[0][x] = dp[1][i]+(h[x]-h[i]);
                        state[x] = true;
                    }else if(h[x]<h[i] && (dp[1][x]<dp[0][i]||dp[1][x]<dp[1][i])){
                        dp[1][x] = max(dp[0][i],dp[1][i]);
                        state[x] = false;
                    }
                }
            }
        }
    }
    cout << max(dp[0][0],dp[1][0]) << endl;


}
0