結果
問題 | No.2100 [Cherry Alpha C] Two-way Steps |
ユーザー | twooimp2 |
提出日時 | 2024-03-06 21:23:30 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,352 bytes |
コンパイル時間 | 7,075 ms |
コンパイル使用メモリ | 305,004 KB |
実行使用メモリ | 21,968 KB |
最終ジャッジ日時 | 2024-03-06 21:23:45 |
合計ジャッジ時間 | 14,026 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,676 KB |
testcase_01 | AC | 1 ms
6,676 KB |
testcase_02 | AC | 2 ms
6,676 KB |
testcase_03 | AC | 2 ms
6,676 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 23 ms
6,676 KB |
testcase_11 | WA | - |
testcase_12 | AC | 46 ms
9,088 KB |
testcase_13 | WA | - |
testcase_14 | AC | 31 ms
7,296 KB |
testcase_15 | WA | - |
testcase_16 | AC | 34 ms
7,552 KB |
testcase_17 | AC | 31 ms
14,464 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 32 ms
7,424 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 49 ms
8,320 KB |
testcase_35 | AC | 50 ms
7,680 KB |
testcase_36 | AC | 35 ms
7,168 KB |
testcase_37 | AC | 34 ms
7,552 KB |
testcase_38 | AC | 36 ms
7,680 KB |
testcase_39 | AC | 28 ms
8,320 KB |
testcase_40 | AC | 29 ms
8,320 KB |
testcase_41 | AC | 29 ms
8,320 KB |
testcase_42 | AC | 29 ms
8,192 KB |
testcase_43 | AC | 28 ms
8,320 KB |
testcase_44 | AC | 53 ms
20,552 KB |
testcase_45 | AC | 52 ms
20,552 KB |
testcase_46 | AC | 54 ms
20,552 KB |
testcase_47 | AC | 54 ms
20,552 KB |
ソースコード
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; using ll=long long; void IO(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main(){ IO(); ll n,m; cin>>n>>m; vector<ll> h(n); for(ll i=0;i<n;i++){ cin>>h[i]; } vector<vector<ll>> G(n); for(ll i=0;i<m;i++){ ll x,y; cin>>x>>y; x--; y--; G[x].push_back(y); G[y].push_back(x); } vector<vector<ll>> dp(n,vector<ll>(2,-1e18)); dp[0][0]=0; for(ll i=0;i<n;i++){ for(ll j:G[i]){ if(i<j){ if(h[i]<h[j]){ dp[j][1]=max(dp[j][1],dp[i][0]+h[j]-h[i]); }else{ dp[j][0]=max(dp[j][0],max(dp[i][0],dp[i][1])); } } } } vector<vector<ll>> dp2(n,vector<ll>(2,-1e18)); dp2[n-1][0]=0; for(ll i=n-1;i>=0;i--){ for(ll j:G[i]){ if(i>j){ if(h[i]<h[j]){ dp2[j][1]=max(dp2[j][1],dp2[i][0]+h[j]-h[i]); }else{ dp2[j][0]=max(dp2[j][0],max(dp2[i][0],dp2[i][1])); } } } } ll ans1=max(dp[n-1][0],dp[n-1][1]); if(ans1==-1e18){ cout<<-1<<endl; }else{ cout<<ans1<<endl; } ll ans2=max(dp2[0][0],dp2[0][1]); if(ans2==-1e18){ cout<<-1<<endl; }else{ cout<<ans2<<endl; } }