結果

問題 No.783 門松計画
ユーザー coco18000coco18000
提出日時 2019-01-11 22:51:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,451 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 167,852 KB
実行使用メモリ 104,892 KB
最終ジャッジ日時 2023-08-20 11:39:46
合計ジャッジ時間 7,884 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
104,724 KB
testcase_01 AC 46 ms
104,600 KB
testcase_02 WA -
testcase_03 AC 46 ms
104,564 KB
testcase_04 AC 46 ms
104,588 KB
testcase_05 WA -
testcase_06 AC 47 ms
104,608 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 46 ms
104,564 KB
testcase_10 AC 760 ms
104,796 KB
testcase_11 AC 1,429 ms
104,592 KB
testcase_12 AC 1,089 ms
104,568 KB
testcase_13 AC 82 ms
104,616 KB
testcase_14 AC 253 ms
104,788 KB
testcase_15 AC 116 ms
104,608 KB
testcase_16 AC 53 ms
104,616 KB
testcase_17 AC 76 ms
104,652 KB
testcase_18 WA -
testcase_19 AC 220 ms
104,564 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 45 ms
104,616 KB
testcase_24 AC 156 ms
104,616 KB
testcase_25 AC 78 ms
104,688 KB
testcase_26 AC 110 ms
104,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int L[60], W[60];

//! [i番目に][kを置いた時に][i-1番目にjを置いている時の][コストcとなるようなもので]=最大のながさ
ll dp[60][60][60][60];

int main()
{
    int N, C;
    cin >> N >> C;
    REP(i, N)
    {
        cin >> L[i];
    }
    REP(i, N)
    {
        cin >> W[i];
    }
    REP(i, 60)
    {
        REP(j, 60)
        {
            REP(k, 60)
            {
                REP(l, 60)
                {
                    dp[i][j][k][l] = 0;
                }
            }
        }
    }

    //! 偶数番目を小さいものにする
    ll max = 0;
    REP(i, 55)
    {
        REP(j, N)
        {
            REP(c, C + 1)
            {
                if (c - W[j] < 0)
                    continue;
                REP(k, N)
                {
                    REP(l, N + 1)
                    {
                        if (j + 1 == l)
                            continue;
                        if ((i + 1) % 2 == 1)
                        {
                            if (L[k] >= L[j])
                                continue;
                        }
                        else
                        {
                            if (L[k] <= L[j])
                                continue;
                        }
                        dp[i + 1][j + 1][k + 1][c] = std::max(dp[i + 1][j + 1][k + 1][c], dp[i][k + 1][l][c - W[j]] + L[j]);
                    }
                }
            }
        }
    }
    REP(i, 55)
    {
        REP(j, N)
        {
            REP(k, N)
            {
                REP(c, C + 1)
                {
                    max = std::max(max, dp[i + 1][j + 1][k + 1][c]);
                }
            }
        }
    }
    REP(i, 60)
    {
        REP(j, 60)
        {
            REP(k, 60)
            {
                REP(l, 60)
                {
                    dp[i][j][k][l] = 0;
                }
            }
        }
    }

    //! 奇数番目を小さいものにする
    REP(i, 55)
    {
        REP(j, N)
        {
            REP(c, C + 1)
            {
                if (c - W[j] < 0)
                    continue;
                REP(k, N)
                {
                    REP(l, N + 1)
                    {
                        if (j + 1 == l)
                            continue;
                        if ((i + 1) % 2 == 1)
                        {
                            if (L[k] <= L[j])
                                continue;
                        }
                        else
                        {
                            if (L[k] >= L[j])
                                continue;
                        }
                        dp[i + 1][j + 1][k + 1][c] = std::max(dp[i + 1][j + 1][k + 1][c], dp[i][k + 1][l][c - W[j]] + L[j]);
                    }
                }
            }
        }
    }
    REP(i, 55)
    {
        REP(j, N)
        {
            REP(k, N)
            {
                REP(c, C + 1)
                {
                    max = std::max(max, dp[i + 1][j + 1][k + 1][c]);
                }
            }
        }
    }
    cout << max << endl;
    return 0;
}
0