結果

問題 No.783 門松計画
ユーザー risujirohrisujiroh
提出日時 2019-01-11 22:20:11
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,773 bytes
コンパイル時間 1,739 ms
使用メモリ 35,308 KB
最終ジャッジ日時 2023-02-23 17:27:06
合計ジャッジ時間 3,170 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 3 ms
7,724 KB
testcase_01 AC 17 ms
14,956 KB
testcase_02 AC 4 ms
7,648 KB
testcase_03 AC 1 ms
7,604 KB
testcase_04 AC 1 ms
7,612 KB
testcase_05 AC 3 ms
9,668 KB
testcase_06 AC 2 ms
9,784 KB
testcase_07 AC 1 ms
9,708 KB
testcase_08 AC 1 ms
7,592 KB
testcase_09 AC 3 ms
7,564 KB
testcase_10 AC 60 ms
35,308 KB
testcase_11 AC 63 ms
35,272 KB
testcase_12 AC 114 ms
35,196 KB
testcase_13 AC 48 ms
35,268 KB
testcase_14 AC 49 ms
33,916 KB
testcase_15 AC 6 ms
9,692 KB
testcase_16 AC 3 ms
9,708 KB
testcase_17 AC 36 ms
28,072 KB
testcase_18 AC 2 ms
7,572 KB
testcase_19 AC 24 ms
19,164 KB
testcase_20 AC 6 ms
7,572 KB
testcase_21 AC 3 ms
7,656 KB
testcase_22 AC 2 ms
7,568 KB
testcase_23 AC 5 ms
7,672 KB
testcase_24 AC 10 ms
9,140 KB
testcase_25 AC 10 ms
9,668 KB
testcase_26 AC 31 ms
22,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0