結果

問題 No.617 Nafmo、買い出しに行く
ユーザー face4face4
提出日時 2018-04-28 16:48:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 72,680 KB
実行使用メモリ 8,664 KB
最終ジャッジ日時 2023-09-10 07:51:24
合計ジャッジ時間 2,558 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 16 ms
4,380 KB
testcase_03 AC 39 ms
4,780 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 67 ms
5,688 KB
testcase_06 AC 135 ms
8,608 KB
testcase_07 AC 135 ms
8,664 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 102 ms
6,996 KB
testcase_11 AC 123 ms
7,792 KB
testcase_12 AC 67 ms
5,444 KB
testcase_13 AC 42 ms
4,776 KB
testcase_14 AC 55 ms
4,956 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>

using namespace std;

int main(){
    int n , k;
    cin >> n >> k;
    vector<vector<bool> > dp(n+1, vector<bool>(k+1));

    for(int i = 0; i <= n; i++){
        dp[i][0] = true;
    }

    for(int i = 0; i <= n; i++){
        for(int j = 1; j <= k; j++){
           dp[i][j] = false;
        }
    }

    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        for(int j = 0; j <= k; j++){
            if(dp[i-1][j] && (j + a) <= k){
                dp[i][j+a] = true;
            }
            if(dp[i-1][j]){
                dp[i][j] = true;
            }
        }
    }

    for(int i = k; i >= 0; i--){
        if(dp[n][i]){
            cout << i << endl;
            return 0;
        }
    }
}
0