結果
問題 | No.2100 [Cherry Alpha C] Two-way Steps |
ユーザー |
|
提出日時 | 2022-10-14 23:31:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,125 bytes |
コンパイル時間 | 1,433 ms |
コンパイル使用メモリ | 110,844 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-06-26 17:27:07 |
合計ジャッジ時間 | 8,457 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 WA * 8 |
ソースコード
#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;}