結果

問題 No.783 門松計画
ユーザー rickythetarickytheta
提出日時 2019-01-11 21:58:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 145,336 KB
実行使用メモリ 5,940 KB
最終ジャッジ日時 2023-09-30 18:38:41
合計ジャッジ時間 2,174 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,688 KB
testcase_01 AC 3 ms
5,656 KB
testcase_02 AC 3 ms
5,788 KB
testcase_03 AC 3 ms
5,696 KB
testcase_04 AC 3 ms
5,652 KB
testcase_05 AC 3 ms
5,716 KB
testcase_06 AC 3 ms
5,692 KB
testcase_07 AC 3 ms
5,764 KB
testcase_08 AC 3 ms
5,656 KB
testcase_09 AC 3 ms
5,920 KB
testcase_10 AC 6 ms
5,664 KB
testcase_11 AC 20 ms
5,760 KB
testcase_12 AC 11 ms
5,724 KB
testcase_13 AC 4 ms
5,716 KB
testcase_14 AC 4 ms
5,780 KB
testcase_15 AC 3 ms
5,740 KB
testcase_16 AC 4 ms
5,940 KB
testcase_17 AC 3 ms
5,656 KB
testcase_18 AC 3 ms
5,668 KB
testcase_19 AC 4 ms
5,780 KB
testcase_20 AC 3 ms
5,716 KB
testcase_21 AC 3 ms
5,828 KB
testcase_22 AC 3 ms
5,780 KB
testcase_23 AC 4 ms
5,656 KB
testcase_24 AC 4 ms
5,656 KB
testcase_25 AC 3 ms
5,780 KB
testcase_26 AC 4 ms
5,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int n,c;
int l[52], w[52];

int dp[52][4][52][52];
const int INF = 252521;

int main(){
    scanf("%d%d",&n,&c);
    REP(i,n)scanf("%d",l+i);
    REP(i,n)scanf("%d",w+i);
    REP(i,52)REP(f,4)REP(j,52)REP(k,52)dp[i][f][j][k] = -INF;
    dp[0][0][0][51] = dp[0][0][51][0] = 0;
    REP(sw,c)REP(f,4)REP(b2,52)REP(b1,52)if(dp[sw][f][b2][b1]>=0){
        REP(i,n){
            if(b2==b1 || b2==l[i] || b1==l[i])continue;
            if(b2<b1 && b1<l[i])continue;
            if(b2>b1 && b1>l[i])continue;
            int nw = sw + w[i];
            if(nw>c)continue;
            int nf = min(3,f+1);
            dp[nw][nf][b1][l[i]] = max(dp[nw][nf][b1][l[i]], dp[sw][f][b2][b1] + l[i]);
        }
    }
    int ans = 0;
    REP(i,c+1)REP(j,50)REP(k,50)ans = max(ans, dp[i][3][j+1][k+1]);
    printf("%d\n",ans);
    return 0;
}
0