結果

問題 No.783 門松計画
ユーザー treeonetreeone
提出日時 2019-01-12 00:43:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,690 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 202,544 KB
実行使用メモリ 5,856 KB
最終ジャッジ日時 2023-09-30 18:40:18
合計ジャッジ時間 3,717 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,632 KB
testcase_01 AC 13 ms
5,572 KB
testcase_02 AC 5 ms
5,620 KB
testcase_03 AC 3 ms
5,852 KB
testcase_04 AC 3 ms
5,764 KB
testcase_05 AC 5 ms
5,632 KB
testcase_06 AC 5 ms
5,628 KB
testcase_07 AC 4 ms
5,564 KB
testcase_08 AC 3 ms
5,644 KB
testcase_09 AC 5 ms
5,588 KB
testcase_10 AC 38 ms
5,700 KB
testcase_11 AC 47 ms
5,808 KB
testcase_12 AC 101 ms
5,592 KB
testcase_13 AC 28 ms
5,596 KB
testcase_14 AC 29 ms
5,568 KB
testcase_15 AC 7 ms
5,704 KB
testcase_16 AC 5 ms
5,768 KB
testcase_17 AC 20 ms
5,576 KB
testcase_18 AC 4 ms
5,580 KB
testcase_19 AC 15 ms
5,696 KB
testcase_20 AC 8 ms
5,592 KB
testcase_21 AC 5 ms
5,704 KB
testcase_22 AC 5 ms
5,576 KB
testcase_23 AC 6 ms
5,564 KB
testcase_24 AC 9 ms
5,856 KB
testcase_25 AC 8 ms
5,692 KB
testcase_26 AC 17 ms
5,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int dp[52][52][52], nxt[52][52][52];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, c;
    cin >> n >> c;
    vector<int> l(n), w(n);
    rep(i, 0, n) cin >> l[i];
    rep(i, 0, n) cin >> w[i];
    rep(i, 0, 52) rep(j, 0, 52) rep(k, 0, 52) dp[i][j][k] = -1;
    dp[0][0][0] = 0;
    int ans = 0;
    rep(i, 0, c){
        rep(j, 0, 52) rep(k, 0, 52) rep(m, 0, 52) nxt[j][k][m] = -1;
        rep(j, 0, c){
            rep(k, 0, 52){
                rep(m, 0, 52){
                    if(dp[j][k][m] == -1) continue;
                    rep(p, 0, n){
                        if(max({k, m, l[p]}) == m || min({k, m, l[p]}) == m || i < 2){
                            if((k != m && m != l[p] && k != l[p]) || i < 2){
                                if(j + w[p] <= c){
                                    nxt[j + w[p]][m][l[p]] = max(nxt[j + w[p]][m][l[p]], dp[j][k][m] + l[p]);
                                }
                            }
                        }
                    }
                }
            }
        }
        swap(dp, nxt);
        if(i >= 2){
            rep(j, 0, c + 1){
                rep(k, 1, 52){
                    rep(m, 1, 52){
                        ans = max(ans, dp[j][k][m]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
0