結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー dyktr_06dyktr_06
提出日時 2022-10-14 22:12:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 2,643 bytes
コンパイル時間 1,802 ms
コンパイル使用メモリ 174,404 KB
実行使用メモリ 21,764 KB
最終ジャッジ日時 2023-09-08 21:56:37
合計ジャッジ時間 6,843 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 83 ms
15,772 KB
testcase_05 AC 61 ms
12,588 KB
testcase_06 AC 13 ms
5,696 KB
testcase_07 AC 15 ms
6,588 KB
testcase_08 AC 83 ms
19,784 KB
testcase_09 AC 58 ms
10,860 KB
testcase_10 AC 25 ms
5,748 KB
testcase_11 AC 57 ms
13,956 KB
testcase_12 AC 43 ms
8,788 KB
testcase_13 AC 51 ms
15,960 KB
testcase_14 AC 33 ms
6,912 KB
testcase_15 AC 53 ms
15,120 KB
testcase_16 AC 36 ms
7,360 KB
testcase_17 AC 35 ms
14,264 KB
testcase_18 AC 52 ms
16,096 KB
testcase_19 AC 99 ms
19,292 KB
testcase_20 AC 20 ms
7,172 KB
testcase_21 AC 40 ms
9,592 KB
testcase_22 AC 35 ms
7,020 KB
testcase_23 AC 75 ms
17,004 KB
testcase_24 AC 116 ms
21,672 KB
testcase_25 AC 112 ms
21,740 KB
testcase_26 AC 112 ms
21,524 KB
testcase_27 AC 108 ms
21,648 KB
testcase_28 AC 112 ms
21,512 KB
testcase_29 AC 109 ms
21,764 KB
testcase_30 AC 110 ms
21,680 KB
testcase_31 AC 120 ms
21,596 KB
testcase_32 AC 112 ms
21,568 KB
testcase_33 AC 114 ms
21,420 KB
testcase_34 AC 44 ms
7,936 KB
testcase_35 AC 39 ms
7,336 KB
testcase_36 AC 39 ms
6,964 KB
testcase_37 AC 36 ms
7,344 KB
testcase_38 AC 43 ms
7,400 KB
testcase_39 AC 31 ms
8,240 KB
testcase_40 AC 32 ms
8,132 KB
testcase_41 AC 31 ms
8,252 KB
testcase_42 AC 31 ms
7,940 KB
testcase_43 AC 31 ms
8,144 KB
testcase_44 AC 58 ms
20,212 KB
testcase_45 AC 57 ms
20,376 KB
testcase_46 AC 57 ms
20,276 KB
testcase_47 AC 58 ms
20,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void in(T& ...)’ 内:
main.cpp:28:55: 警告: fold-expressions only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   28 | template<class... T> void in(T&... a){ (cin >> ... >> a); }
      |                                                       ^
main.cpp: 関数 ‘void out(const T&, const Ts& ...)’ 内:
main.cpp:30:112: 警告: fold-expressions only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   30 | template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
      |                                                                                                                ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())

typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef vector<string> vst;
typedef vector<double> vd;
typedef pair<long long, long long> P;

const long long INF = 0x1fffffffffffffff;
const long long MOD = 1000000007;
const long double PI = acos(-1);
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T, class U> inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; }
template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; }
template<class... T> void in(T&... a){ (cin >> ... >> a); }
void out(){ cout << '\n'; }
template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T, class U> void inGraph(vector<vector<T>>& G, U n, U m, bool directed = false){ G.resize(n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); if(!directed) G[b].push_back(a); } }

ll n, m;
vll h;
vector<vector<ll>> G;

void input(){
    in(n, m);
    vin(h, n);
    inGraph(G, n, m);
}
 
void solve(){
    vector<vector<ll>> dp1(n + 1, vector<ll>(2, -INF)), dp2(n + 1, vector<ll>(2, -INF));
    dp1[0][0] = 0;
    dp1[0][1] = 0;
    dp2[n - 1][0] = 0;
    dp2[n - 1][1] = 0;
    rep(i, n){
        for(auto x : G[i]){
            if(x < i) continue;
            if(h[i] < h[x]){
                chmax(dp1[x][0], dp1[i][1] + h[x] - h[i]);
            }else{
                chmax(dp1[x][1], max(dp1[i][0], dp1[i][1]));
            }
        }
    } 
    rrep(i, n){
        for(auto x : G[i]){
            if(x > i) continue;
            if(h[i] < h[x]){
                chmax(dp2[x][0], dp2[i][1] + h[x] - h[i]);
            }else{
                chmax(dp2[x][1], max(dp2[i][0], dp2[i][1]));
            }
        }
    }
    ll ans1 = max(dp1[n - 1][0], dp1[n - 1][1]), ans2 = max(dp2[0][0], dp2[0][1]);
    if(ans1 < 0){
        out(-1);
    }else{
        out(ans1);
    }
    if(ans2 < 0){
        out(-1);
    }else{
        out(ans2);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    input();
    solve();
}
0