結果

問題 No.783 門松計画
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-05 03:29:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,976 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 167,492 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 18:44:23
合計ジャッジ時間 2,640 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 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 3 ms
4,376 KB
testcase_11 AC 25 ms
4,376 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int dp[51][51][51];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, C;
    cin >> N >> C;
    vector<int> Ls(N, 0);
    vector<int> Ws(N, 0);
    for (auto & l: Ls) cin >> l;
    int L = *max_element(Ls.begin(), Ls.end());
    for (auto & w: Ws) cin >> w;
    for (int c = 0; c <= C; ++c){
        for (int a = 0; a <= 50; ++a){
            for (int b = 0; b <= 50; ++b){
                dp[c][a][b] = 0;
            }
        }
    }
    for (int i = 0; i < N; ++i){
        for (int j = 0; j < N; ++j){
            if (Ls[i] == Ls[j]) continue;
            int c = Ws[i] + Ws[j];
            if (c > C) continue;
            for (int k = 0; k < N; ++k){
                if (Ls[i] == Ls[k] or Ls[j] == Ls[k]) continue;
                if (Ls[i] > Ls[j] and Ls[j] > Ls[k]) continue;
                if (Ls[i] < Ls[j] and Ls[j] < Ls[k]) continue;
                if (c + Ws[k] > C) continue;
                if (dp[c + Ws[k]][Ls[k]][Ls[j]] < Ls[i] + Ls[j] + Ls[k]){
                    dp[c + Ws[k]][Ls[k]][Ls[j]] = Ls[i] + Ls[j] + Ls[k];
                }
            }
        }
    }
    for (int c = 1; c < C; ++c){
        for (int a = 1; a <= L; ++a){
            for (int b = 1; b <= L; ++b){
                if (dp[c][a][b] == 0) continue;
                for (int i = 0; i < N; ++i){
                    if (c + Ws[i] > C) continue;
                    if (a == Ls[i] or b == Ls[i]) continue;
                    if (Ls[i] > a and a > b) continue;
                    if (Ls[i] < a and a < b) continue;
                    dp[c + Ws[i]][Ls[i]][a] = max(dp[c + Ws[i]][Ls[i]][a], dp[c][a][b] + Ls[i]);
                }
            }
        }
    }
    int ans = 0;
    for (int c = 1; c <= C; ++c){
        for (int a = 1; a <= L; ++a){
            for (int b = 1; b <= L; ++b){
                ans = max(ans, dp[c][a][b]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

0