結果

問題 No.783 門松計画
ユーザー finefine
提出日時 2019-01-11 22:32:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 165,344 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 18:39:26
合計ジャッジ時間 2,475 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int n, c;
int L[55], W[55];
int dp[55][55][55];

int solve(int i, int j, int x) {
    int& res = dp[i][j][x];
    if (res >= 0) return res;

    res = 0;
    for (int k = 0; k < n; k++) {
        if (L[i] == L[k] || L[j] == L[k]) continue;
        if (min({L[i], L[j], L[k]}) != L[j] && max({L[i], L[j], L[k]}) != L[j]) continue;
        if (x < W[k]) continue;
        res = max(res, L[k] + solve(j, k, x - W[k]));
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> c;
    for (int i = 0; i < n; i++) {
        cin >> L[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> W[i];
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (L[i] == L[j]) continue;
            for (int k = 0; k <= c - W[i] - W[j]; k++) {
                dp[i][j][k] = -1;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (L[i] == L[j]) continue;
            if (c < W[i] + W[j]) continue;
            int tmp = solve(i, j, c - W[i] - W[j]);
            if (tmp == 0) continue;
            ans = max(ans, tmp + L[i] + L[j]);
        }
    }
    cout << ans << endl;
    return 0;
}
0