結果

問題 No.783 門松計画
ユーザー coco18000coco18000
提出日時 2019-02-03 22:24:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,635 bytes
コンパイル時間 2,584 ms
コンパイル使用メモリ 150,372 KB
実行使用メモリ 75,308 KB
最終ジャッジ日時 2023-08-23 13:03:12
合計ジャッジ時間 6,604 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 388 ms
74,328 KB
testcase_11 AC 666 ms
75,308 KB
testcase_12 AC 530 ms
74,936 KB
testcase_13 AC 28 ms
13,532 KB
testcase_14 AC 121 ms
37,204 KB
testcase_15 AC 17 ms
9,504 KB
testcase_16 AC 4 ms
4,476 KB
testcase_17 AC 23 ms
13,464 KB
testcase_18 WA -
testcase_19 AC 83 ms
29,084 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 31 ms
13,128 KB
testcase_25 AC 12 ms
8,652 KB
testcase_26 AC 38 ms
18,684 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;

pll A[55];

//! [i番目に][L[j]を置いて][前回置いたものがL[k]][コストがcとなるような]=最大の長さ
ll dp0[55][55][55][55];
ll dp1[55][55][55][55];

int main()
{
    int N, C;
    cin >> N >> C;
    REP(i, N)
    {
        cin >> A[i].first;
    }
    REP(i, N)
    {
        cin >> A[i].second;
    }
    sort(A, A + N, [](pll a, pll b) { return a.first < b.first; });

    //! 奇数番目が小さくなるような門松列
    FOR(i, C + 1, 1)
    {
        REP(j, N)
        {
            REP(k, C + 1)
            {
                if (k - A[j].second < 0)
                    continue;
                REP(m, N)
                {
                    if (i % 2 == 0 && A[m].first >= A[j].first)
                        continue;
                    else if (i % 2 == 1 && A[m].first <= A[j].first)
                        continue;
                    REP(n, N)
                    {
                        if (A[n].first == A[j].first)
                            continue;
                        dp0[i][j][m][k] = std::max(dp0[i][j][m][k], dp0[i - 1][m][n][k - A[j].second] + A[j].first);
                    }
                }
            }
        }
    }
    //! 偶数番目が小さくなるような門松列
    FOR(i, C + 1, 1)
    {
        REP(j, N)
        {
            REP(k, C + 1)
            {
                if (k - A[j].second < 0)
                    continue;
                REP(m, N)
                {
                    if (i % 2 == 0 && (A[m].first <= A[j].first))
                        continue;
                    else if (i % 2 == 1 && A[m].first >= A[j].first)
                        continue;

                    REP(n, N)
                    {
                        if (A[n].first == A[j].first)
                            continue;
                        dp1[i][j][m][k] = std::max(dp1[i][j][m][k], dp1[i - 1][m][n][k - A[j].second] + A[j].first);
                    }
                }
            }
        }
    }

    ll max = 0;
    FOR(i, C + 1, 3)
    {
        REP(j, N)
        {
            REP(k, C + 1)
            {
                REP(n, N)
                {
                    max = std::max(dp0[i][j][n][k], max);
                    max = std::max(dp1[i][j][n][k], max);
                }
            }
        }
    }
    cout << max << endl;
    return 0;
}
0