結果

問題 No.783 門松計画
ユーザー ei1333333ei1333333
提出日時 2019-01-11 21:42:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 841 bytes
コンパイル時間 2,685 ms
コンパイル使用メモリ 198,036 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-20 05:12:49
合計ジャッジ時間 3,449 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 34 ms
4,376 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 3 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

int dp[51][52][52];
int N, L[50], W[50];

bool uku(int a, int b, int c) {
  if(a == b || a == c || b == c) return false;
  int s = min({a, b, c});
  int t = max({a, b, c});
  return (s == b || t == b);
}


int rec(int rest, int l1, int l2) {
  if(~dp[rest][l1][l2]) return dp[rest][l1][l2];
  int ret = 0;
  for(int i = 0; i < N; i++) {
    if(rest - W[i] < 0) continue;
    if(uku(l1, l2, L[i])) ret = max(ret, rec(rest - W[i], l2, L[i]) + L[i]);
  }
  return dp[rest][l1][l2] = ret;
}

int main() {
  int K;
  cin >> N >> K;
  for(int i = 0; i < N; i++) cin >> L[i];
  for(int i = 0; i < N; i++) cin >> W[i];
  memset(dp, -1, sizeof(dp));
  int ret = 0;
  for(int i = 0; i <= 50; i++) {
    for(int j = 0; j <= 50; j++) {
      ret = max(ret, rec(K, i, j));
    }
  }
  cout << ret << endl;
}
0