結果
問題 | No.783 門松計画 |
ユーザー | risujiroh |
提出日時 | 2019-01-11 22:20:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 106 ms / 2,000 ms |
コード長 | 1,773 bytes |
コンパイル時間 | 1,698 ms |
コンパイル使用メモリ | 177,964 KB |
実行使用メモリ | 35,292 KB |
最終ジャッジ日時 | 2023-09-30 18:39:22 |
合計ジャッジ時間 | 3,230 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
4,664 KB |
testcase_01 | AC | 19 ms
14,948 KB |
testcase_02 | AC | 4 ms
5,040 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 3 ms
4,728 KB |
testcase_06 | AC | 3 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,384 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 4 ms
4,504 KB |
testcase_10 | AC | 60 ms
35,232 KB |
testcase_11 | AC | 65 ms
35,292 KB |
testcase_12 | AC | 106 ms
35,276 KB |
testcase_13 | AC | 55 ms
35,244 KB |
testcase_14 | AC | 54 ms
33,900 KB |
testcase_15 | AC | 6 ms
6,720 KB |
testcase_16 | AC | 4 ms
5,020 KB |
testcase_17 | AC | 39 ms
28,120 KB |
testcase_18 | AC | 3 ms
4,376 KB |
testcase_19 | AC | 26 ms
19,144 KB |
testcase_20 | AC | 7 ms
7,076 KB |
testcase_21 | AC | 4 ms
4,976 KB |
testcase_22 | AC | 3 ms
4,416 KB |
testcase_23 | AC | 6 ms
6,428 KB |
testcase_24 | AC | 11 ms
9,140 KB |
testcase_25 | AC | 9 ms
8,784 KB |
testcase_26 | AC | 31 ms
22,832 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using lint = long long int; using ulint = unsigned long long int; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); } template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, c; cin >> n >> c; V<> l(n); for (int i = 0; i < n; ++i) cin >> l[i]; V<> w(n); for (int i = 0; i < n; ++i) cin >> w[i]; if (c < 3) return cout << 0 << '\n', 0; VV< VV<> > dp; assign(dp, c + 1, c + 1, 51, 51, 0); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (l[i] != l[j] and w[i] + w[j] <= c) { dp[2][w[i] + w[j]][l[i]][l[j]] = max(dp[2][w[i] + w[j]][l[i]][l[j]], l[i] + l[j]); } for (int i = 2; i < c; ++i) for (int j = 0; j <= c; ++j) { for (int l0 = 0; l0 <= 50; ++l0) for (int l1 = 0; l1 <= 50; ++l1) if (dp[i][j][l0][l1]) { if (l0 < l1) { for (int k = 0; k < n; ++k) if (l1 > l[k] and l0 != l[k] and j + w[k] <= c) { dp[i + 1][j + w[k]][l1][l[k]] = max(dp[i + 1][j + w[k]][l1][l[k]], dp[i][j][l0][l1] + l[k]); } } else { for (int k = 0; k < n; ++k) if (l1 < l[k] and l0 != l[k] and j + w[k] <= c) { dp[i + 1][j + w[k]][l1][l[k]] = max(dp[i + 1][j + w[k]][l1][l[k]], dp[i][j][l0][l1] + l[k]); } } } } int res = 0; for (int i = 3; i <= c; ++i) for (int j = 0; j <= c; ++j) { for (int l0 = 0; l0 <= 50; ++l0) for (int l1 = 0; l1 <= 50; ++l1) { res = max(res, dp[i][j][l0][l1]); } } cout << res << '\n'; }