結果
問題 | No.2100 [Cherry Alpha C] Two-way Steps |
ユーザー | momoyuu |
提出日時 | 2022-10-14 23:53:35 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,814 bytes |
コンパイル時間 | 3,759 ms |
コンパイル使用メモリ | 253,928 KB |
実行使用メモリ | 17,432 KB |
最終ジャッジ日時 | 2023-09-09 00:51:32 |
合計ジャッジ時間 | 10,539 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 139 ms
13,264 KB |
testcase_05 | AC | 105 ms
10,904 KB |
testcase_06 | AC | 20 ms
4,936 KB |
testcase_07 | AC | 25 ms
5,372 KB |
testcase_08 | AC | 129 ms
15,124 KB |
testcase_09 | AC | 104 ms
10,064 KB |
testcase_10 | WA | - |
testcase_11 | AC | 97 ms
11,288 KB |
testcase_12 | WA | - |
testcase_13 | AC | 79 ms
11,708 KB |
testcase_14 | WA | - |
testcase_15 | AC | 87 ms
11,980 KB |
testcase_16 | WA | - |
testcase_17 | AC | 54 ms
10,288 KB |
testcase_18 | AC | 81 ms
12,116 KB |
testcase_19 | AC | 160 ms
15,944 KB |
testcase_20 | AC | 33 ms
5,824 KB |
testcase_21 | AC | 70 ms
8,632 KB |
testcase_22 | WA | - |
testcase_23 | AC | 120 ms
13,544 KB |
testcase_24 | AC | 172 ms
17,332 KB |
testcase_25 | AC | 175 ms
17,272 KB |
testcase_26 | AC | 178 ms
17,192 KB |
testcase_27 | AC | 173 ms
17,252 KB |
testcase_28 | AC | 172 ms
17,172 KB |
testcase_29 | WA | - |
testcase_30 | AC | 173 ms
17,244 KB |
testcase_31 | WA | - |
testcase_32 | AC | 177 ms
17,252 KB |
testcase_33 | AC | 168 ms
17,288 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 70 ms
9,800 KB |
testcase_40 | AC | 72 ms
9,832 KB |
testcase_41 | AC | 69 ms
9,744 KB |
testcase_42 | AC | 70 ms
10,264 KB |
testcase_43 | AC | 69 ms
9,784 KB |
testcase_44 | AC | 104 ms
14,764 KB |
testcase_45 | AC | 104 ms
14,704 KB |
testcase_46 | AC | 102 ms
14,656 KB |
testcase_47 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template<class t> using vc = vector<t>; template<class t> using vvc = vc<vc<t>>; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vc<int>; using vvi = vvc<int>; using vl = vc<ll>; using vvl = vvc<ll>; #define rep(i,a,b) for (int i = (int)(a); i < (int)(b); i++) #define irep(i,a,b) for (int i = (int)(a); i > (int)(b); i--) #define all(a) a.begin(),a.end() #define print(n) cout << n << '\n' #define pritn(n) print(n) #define printv(n,a) {copy(all(n),ostream_iterator<a>(cout," ")); cout<<"\n";} #define printvv(n,a) {for(auto itr:n) printv(itr,a);} #define rup(a,b) (a+b-1)/b #define input(A,N) rep(i,0,N) cin>>A[i] #define chmax(a,b) a = max(a,b) #define chmin(a,b) a = min(a,b) template< typename T > struct edge{ int from,to; T cost; /* *to:繋がってる先 *cost:辺のコスト */ edge(int from,int to, T cost):from(from),to(to),cost(cost){}; edge &operator=(const int& x){ to = x; return *this; } }; template< typename T > struct graph{ int n; vector<vector<edge<T>>> e; graph(int n):n(n),e(n){} void addedge(int from,int to,T cost){ e[from].emplace_back(from,to,cost); } vector<edge<T>> &operator[](int i) { return e[i]; } }; int main(){ cout << fixed << setprecision(15); int n,m; cin>>n>>m; vl h(n); input(h,n); graph<int> g(n); rep(i,0,m){ int u,v; cin>>u>>v; u--;v--; g.addedge(u,v,1); g.addedge(v,u,1); } vvc<ll> dp(n,vc<ll>(2,-1)); dp[0][0] = 0; dp[0][1] = 0; for(int i = 0;i<n-1;i++){ for(auto e:g[i]){ if(i>=e.to) continue; int ni = e.to; ll d = h[ni] - h[i]; if(d<0){ if(dp[i][0]==-1) continue; chmax(dp[ni][1],dp[i][0]); }else{ if(dp[i][1] == -1) continue; chmax(dp[ni][0],dp[i][1]+d); } } } ll a = max(dp[n-1][0],dp[n-1][1]); for(int i = 0;i<n;i++){ for(int j = 0;j<2;j++) dp[i][j] = -1; } dp[n-1][0] = 0; dp[n-1][1] = 0; for(int i = n-1;i>=1;i--){ for(auto e:g[i]){ if(i<=e.to) continue; int ni = e.to; ll d = h[ni] - h[i]; if(d<0){ if(dp[i][0]!=-1) chmax(dp[ni][1],dp[i][0]); if(dp[i][1]!=-1) chmax(dp[ni][1],dp[i][1]); }else{ if(dp[i][1] == -1) continue; chmax(dp[ni][0],dp[i][1]+d); } } } ll b = max(dp[0][0],dp[0][1]); //printvv(dp,ll); print(a); print(b); //system("pause"); return 0; }