結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー bayashikobayashiko
提出日時 2022-10-15 01:04:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,508 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 206,276 KB
実行使用メモリ 13,232 KB
最終ジャッジ日時 2023-09-09 01:37:43
合計ジャッジ時間 6,369 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 58 ms
10,268 KB
testcase_05 AC 44 ms
8,396 KB
testcase_06 AC 8 ms
4,840 KB
testcase_07 AC 11 ms
5,112 KB
testcase_08 AC 57 ms
11,924 KB
testcase_09 AC 42 ms
7,532 KB
testcase_10 AC 25 ms
4,704 KB
testcase_11 AC 40 ms
9,096 KB
testcase_12 AC 29 ms
6,520 KB
testcase_13 AC 33 ms
9,920 KB
testcase_14 AC 27 ms
5,480 KB
testcase_15 AC 35 ms
9,656 KB
testcase_16 AC 29 ms
5,632 KB
testcase_17 AC 22 ms
8,884 KB
testcase_18 AC 35 ms
10,084 KB
testcase_19 AC 71 ms
11,816 KB
testcase_20 AC 14 ms
5,404 KB
testcase_21 AC 29 ms
6,820 KB
testcase_22 AC 29 ms
5,704 KB
testcase_23 AC 51 ms
10,632 KB
testcase_24 AC 75 ms
13,032 KB
testcase_25 AC 78 ms
13,164 KB
testcase_26 AC 74 ms
13,152 KB
testcase_27 AC 74 ms
13,040 KB
testcase_28 AC 73 ms
13,040 KB
testcase_29 AC 77 ms
13,040 KB
testcase_30 AC 77 ms
13,048 KB
testcase_31 AC 77 ms
13,232 KB
testcase_32 AC 71 ms
13,104 KB
testcase_33 AC 75 ms
13,024 KB
testcase_34 AC 43 ms
6,180 KB
testcase_35 AC 39 ms
5,692 KB
testcase_36 AC 37 ms
5,464 KB
testcase_37 AC 35 ms
5,456 KB
testcase_38 AC 40 ms
6,020 KB
testcase_39 AC 32 ms
5,788 KB
testcase_40 AC 32 ms
6,024 KB
testcase_41 AC 32 ms
5,848 KB
testcase_42 AC 32 ms
5,836 KB
testcase_43 AC 32 ms
5,756 KB
testcase_44 AC 43 ms
12,796 KB
testcase_45 AC 43 ms
12,740 KB
testcase_46 AC 43 ms
12,876 KB
testcase_47 AC 42 ms
12,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#if defined(LOCAL)
#include<stdc++.h>
#else
#include<bits/stdc++.h>
#endif
#include<random>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
//#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define MINF (lint)(2e18)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
//#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//vector<int> bucket[MAX_N/1000];
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
/*#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;*/

int main(void){
    lint N,M;
    cin >> N >> M;
    lint H[N];
    rep(i,N) cin >> H[i];
    vector<int> edge[N];
    rep(i,M){
        int u,v;
        cin >> u >> v;
        u--,v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    lint ldp[N][2],rdp[N][2];
    rep(i,N) rep(j,2) ldp[i][j]=-1,rdp[i][j]=-1;
    ldp[0][0]=0,rdp[N-1][0]=0;
    rep(i,N) rep(j,2){
        if(ldp[i][j]==-1) continue;
        for(auto e:edge[i]){
            if(e<i) continue;
            if(H[e]>H[i]){
                if(j==0) chmax(ldp[e][1],ldp[i][j]+H[e]-H[i]);
            }
            else{
                chmax(ldp[e][0],ldp[i][j]);
            }
        }
    }
    reprev(i,N) rep(j,2){
        if(rdp[i][j]==-1) continue;
        for(auto e:edge[i]){
            if(e>i) continue;
            if(H[e]>H[i]){
                if(j==0) chmax(rdp[e][1],rdp[i][j]+H[e]-H[i]);
            }
            else{
                chmax(rdp[e][0],rdp[i][j]);
            }
        }
    }
    cout << max(ldp[N-1][0],ldp[N-1][1]) << endl;
    cout << max(rdp[0][0],rdp[0][1]) << endl;
}
0