結果

問題 No.783 門松計画
ユーザー koyoprokoyopro
提出日時 2020-01-03 16:44:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,780 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 147,432 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-30 18:44:40
合計ジャッジ時間 2,205 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

/*================================*/

int N,C;
struct Bamboo {
    int l, w;
};

bool is_kadomatsu(int a, int b, int c) {
    if (a==b || b==c || c==a) return false;
    if (!(b < a && b < c) && !(b > a && b > c)) return false;
    return true;
}

signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin>>N>>C;
    
    int L = 50;
    
    vector<Bamboo> B(N);
    REP(i,N) cin >> B[i].l;
    REP(i,N) cin >> B[i].w;
    
    // 2つ前長さ, 1つ前長さ, 所持金 => 累計長さ
    int DP[L+1][L+1][C+1];
    REP(i,L+1)REP(j,L+1)REP(k,C+1)DP[i][j][k]=-1;
    
    DP[0][0][C] = 0;
    
    int ans = 0;
    RREP(k,C+1) REP(i,L+1) REP(j,L+1) {
        if (j == 0 && i != 0) continue; // 2つ前が未定なら一つ前も未定である必要がある
        if (DP[i][j][k] < 0) continue;
        for (auto b : B) {
            if (k < b.w) continue; // 残高不足
            if (i!=0 && j!=0 && !is_kadomatsu(i, j, b.l)) continue;
            int ret = DP[j][b.l][k-b.w] = max(DP[j][b.l][k-b.w], DP[i][j][k] + b.l);
            if(i!=0 && j!=0) ans = max(ans, ret);
        }
    }
    
     cout << ans << endl;
    
    return 0;
}
0