結果

問題 No.783 門松計画
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-02-09 19:28:08
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,321 bytes
コンパイル時間 2,570 ms
コンパイル使用メモリ 209,136 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-28 13:10:18
合計ジャッジ時間 2,997 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll N, C;
    cin >> N >> C;
    vector dp(C+1, vector(51, vector<int>(51, -1e9)));

    auto check = [&](int a, int b, int c){
        if (b == 0 && c == 0) return 1;
        if (c == 0){
            if (b == a) return 0;
            return 1;
        }
        if (a == b || b == c || c == a) return 0;
        if (a > b && b < c) return 1;
        if (a < b && b > c) return 1;
        return 0;
    };

    dp[0][0][0] = 0;

    vector<int> L(N), D(N);
    for (int i=0; i<N; i++) cin >> L[i];
    for (int i=0; i<N; i++) cin >> D[i];

    for (int i=0; i<=C; i++){
        for (int j=0; j<=50; j++){
            for (int k=0; k<=50; k++){
                for (int l=0; l<N; l++){
                    if (i+D[l] > C) continue;
                    if (check(L[l], k, j)){
                        dp[i+D[l]][L[l]][k] = max(dp[i+D[l]][L[l]][k], dp[i][k][j]+L[l]);
                    }
                }
            }
        }
    }

    int ans = 0;
    for (int i=0; i<=C; i++){
        for (int j=1; j<=50; j++){
            for (int k=1; k<=50; k++){
                ans = max(ans, dp[i][j][k]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}
0