結果
問題 | No.2100 [Cherry Alpha C] Two-way Steps |
ユーザー |
|
提出日時 | 2022-10-14 23:11:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,670 bytes |
コンパイル時間 | 1,547 ms |
コンパイル使用メモリ | 106,972 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-06-26 17:03:38 |
合計ジャッジ時間 | 7,834 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 44 WA * 4 |
ソースコード
#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<long long> dp(n,-1);vector<bool> state(n,false); // その階段にくるときに上がったかdp[0]=0;for(int i =0;i<n;i++){if(dp[i]!=-1){for(auto x:list[i]){if(x<i) continue;if(h[i]<h[x] && state[i] == false && dp[x] < dp[i]+(h[x]-h[i])) {dp[x] = dp[i]+(h[x]-h[i]);state[x] = true;}else if(h[x]<h[i] && dp[x]<dp[i]){dp[x] = dp[i];state[x] = false;}}}}cout << dp[n-1] << endl;dp.clear();dp.resize(n,-1);state.clear();state.resize(n,false);dp[n-1]=0;for(int i =n-1;0<=i;i--){if(dp[i]!=-1){for(auto x:list[i]){if(i<x) continue;if(h[i]<h[x] && state[i] == false && dp[x] < dp[i]+(h[x]-h[i])) {dp[x] = dp[i]+(h[x]-h[i]);state[x] = true;}else if(h[x]<h[i] && dp[x]<dp[i]){dp[x] = dp[i];state[x] = false;}}}}cout << dp[0] << endl;}