結果
問題 | No.2100 [Cherry Alpha C] Two-way Steps |
ユーザー | wanui |
提出日時 | 2022-10-15 00:36:11 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 96 ms / 2,000 ms |
コード長 | 2,662 bytes |
コンパイル時間 | 2,031 ms |
コンパイル使用メモリ | 202,992 KB |
実行使用メモリ | 20,552 KB |
最終ジャッジ日時 | 2023-09-09 01:17:33 |
合計ジャッジ時間 | 7,020 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,188 KB |
testcase_01 | AC | 3 ms
6,080 KB |
testcase_02 | AC | 4 ms
6,184 KB |
testcase_03 | AC | 3 ms
6,108 KB |
testcase_04 | AC | 69 ms
10,752 KB |
testcase_05 | AC | 52 ms
10,080 KB |
testcase_06 | AC | 11 ms
6,888 KB |
testcase_07 | AC | 13 ms
7,000 KB |
testcase_08 | AC | 63 ms
9,896 KB |
testcase_09 | AC | 51 ms
10,608 KB |
testcase_10 | AC | 30 ms
8,488 KB |
testcase_11 | AC | 47 ms
9,992 KB |
testcase_12 | AC | 36 ms
9,360 KB |
testcase_13 | AC | 37 ms
8,476 KB |
testcase_14 | AC | 33 ms
9,140 KB |
testcase_15 | AC | 39 ms
8,728 KB |
testcase_16 | AC | 35 ms
9,304 KB |
testcase_17 | AC | 20 ms
7,348 KB |
testcase_18 | AC | 36 ms
8,240 KB |
testcase_19 | AC | 76 ms
11,540 KB |
testcase_20 | AC | 18 ms
7,436 KB |
testcase_21 | AC | 34 ms
9,060 KB |
testcase_22 | AC | 34 ms
9,384 KB |
testcase_23 | AC | 57 ms
10,268 KB |
testcase_24 | AC | 90 ms
11,472 KB |
testcase_25 | AC | 90 ms
11,820 KB |
testcase_26 | AC | 92 ms
11,576 KB |
testcase_27 | AC | 90 ms
11,720 KB |
testcase_28 | AC | 92 ms
11,460 KB |
testcase_29 | AC | 88 ms
11,908 KB |
testcase_30 | AC | 96 ms
11,744 KB |
testcase_31 | AC | 91 ms
11,952 KB |
testcase_32 | AC | 93 ms
11,516 KB |
testcase_33 | AC | 91 ms
11,544 KB |
testcase_34 | AC | 51 ms
10,592 KB |
testcase_35 | AC | 45 ms
10,344 KB |
testcase_36 | AC | 43 ms
9,772 KB |
testcase_37 | AC | 42 ms
10,040 KB |
testcase_38 | AC | 48 ms
10,204 KB |
testcase_39 | AC | 39 ms
11,160 KB |
testcase_40 | AC | 39 ms
11,220 KB |
testcase_41 | AC | 39 ms
10,868 KB |
testcase_42 | AC | 39 ms
10,880 KB |
testcase_43 | AC | 40 ms
11,220 KB |
testcase_44 | AC | 54 ms
20,552 KB |
testcase_45 | AC | 51 ms
20,504 KB |
testcase_46 | AC | 48 ms
18,964 KB |
testcase_47 | AC | 48 ms
18,876 KB |
ソースコード
#include <bits/stdc++.h> // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18; void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);} void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);} void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);} void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);} void ioinit() { cout<<fixed<<setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); } #define debug1(a) { cerr<<#a<<":"<<a<<endl; } #define debug2(a,b) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<endl; } #define debug3(a,b,c) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<endl; } #define debug4(a,b,c,d) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<" "<<#d<<":"<<d<<endl; } // clang-format on const ll V = 100005; vector<vector<ll>> edgmap(V); vector<ll> height(V); ll N; ll memo1[V][2]; bool done1[V][2]; ll dp1(ll u, ll up) { if (done1[u][up]) return memo1[u][up]; done1[u][up] = true; if (u == N) { return memo1[u][up] = 0; } ll ans = -INF; for (auto v : edgmap[u]) { if (u > v) continue; if (up && height[v] > height[u]) continue; if (height[v] > height[u]) { ll diff = height[v] - height[u]; ans = max(ans, diff + dp1(v, 1)); } else { ans = max(ans, dp1(v, 0)); } } return memo1[u][up] = ans; } ll memo2[V][2]; bool done2[V][2]; ll dp2(ll u, ll up) { if (done2[u][up]) return memo2[u][up]; done2[u][up] = true; if (u == 1) { return memo2[u][up] = 0; } ll ans = -INF; for (auto v : edgmap[u]) { if (u < v) continue; if (up && height[v] > height[u]) continue; if (height[v] > height[u]) { ll diff = height[v] - height[u]; ans = max(ans, diff + dp2(v, 1)); } else { ans = max(ans, dp2(v, 0)); } } return memo2[u][up] = ans; } int main() { ioinit(); ll M; cin >> N >> M; for (ll i = 1; i <= N; i++) { cin >> height[i]; } for (ll i = 0; i < M; i++) { ll x, y; cin >> x >> y; edgmap[x].push_back(y); edgmap[y].push_back(x); } ll a1 = dp1(1, 0); if (a1 < -INF / 2) a1 = -1; print(a1); ll a2 = dp2(N, 0); if (a2 < -INF / 2) a2 = -1; print(a2); return 0; }