結果
問題 | No.417 チューリップバブル |
ユーザー | ttkkggww |
提出日時 | 2020-04-01 15:50:30 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,306 bytes |
コンパイル時間 | 1,605 ms |
コンパイル使用メモリ | 172,036 KB |
実行使用メモリ | 630,300 KB |
最終ジャッジ日時 | 2023-09-09 05:21:34 |
合計ジャッジ時間 | 16,723 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
25,948 KB |
testcase_01 | AC | 31 ms
25,868 KB |
testcase_02 | AC | 31 ms
25,944 KB |
testcase_03 | AC | 31 ms
25,812 KB |
testcase_04 | AC | 8 ms
11,580 KB |
testcase_05 | AC | 9 ms
11,664 KB |
testcase_06 | AC | 36 ms
29,900 KB |
testcase_07 | AC | 36 ms
29,916 KB |
testcase_08 | WA | - |
testcase_09 | AC | 71 ms
54,560 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 461 ms
316,704 KB |
testcase_25 | WA | - |
testcase_26 | AC | 322 ms
222,664 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 5 ms
11,600 KB |
testcase_33 | AC | 19 ms
19,660 KB |
testcase_34 | AC | 160 ms
160,988 KB |
testcase_35 | MLE | - |
testcase_36 | MLE | - |
testcase_37 | MLE | - |
testcase_38 | MLE | - |
testcase_39 | MLE | - |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; ll dp[201][200][2001]; //dp[i][j][k] //iを頂点とした、jをの子までを選んでkのタイムでの最大の税収 //iそれぞれでナップサックみたいな感じ vector<vector<pair<int,int>>> M; vector<int> tax; void dfs(int now,int p = -1) { //cout<<now<<endl; for(int i = 0;i<201;i++) { for(int j = 0;j <2001;j++) { dp[now][i][j] = tax[now]; } } int I = 0; for(int i = 0;i<M[now].size();i++) { if(M[now][i].first!=p) { dfs(M[now][i].first,now); for(int j = 0;j<2001;j++) { if(j-M[now][i].second<0) { dp[now][I+1][j] = dp[now][I][j]; continue; } for(int k = 0;j-M[now][i].second-k>=0;k++) { dp[now][I+1][j] = max(max(dp[now][I][j], dp[now][I+1][j]), dp[now][I][j-M[now][i].second-k] +dp[M[now][i].first][0][k]); } } I++; } } for(int i = 0;i<2001;i++) { dp[now][0][i] = dp[now][I][i]; } } int main() { int n; cin >> n; int m; cin >> m; tax = vector<int>(n); for(int i = 0;i<n;i++) { cin >> tax[i]; } M = vector<vector<pair<int,int>>>(n); for(int i = 0;i<n-1;i++) { int x,y,z; cin >> x >> y >> z; M[x].emplace_back(y,z); M[y].emplace_back(x,z); } dfs(0); cout<<dp[0][0][m/2]<<endl; return 0; }