結果

問題 No.617 Nafmo、買い出しに行く
ユーザー かにかに
提出日時 2017-12-17 14:41:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 198,332 KB
実行使用メモリ 11,328 KB
最終ジャッジ日時 2023-08-22 04:22:27
合計ジャッジ時間 3,171 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,684 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 8 ms
5,072 KB
testcase_03 AC 20 ms
7,604 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 32 ms
9,480 KB
testcase_06 AC 61 ms
11,328 KB
testcase_07 AC 59 ms
11,328 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 45 ms
9,472 KB
testcase_11 AC 56 ms
10,252 KB
testcase_12 AC 32 ms
7,716 KB
testcase_13 AC 21 ms
7,424 KB
testcase_14 AC 25 ms
7,428 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;
int dp[2000000];
void solve() {
    int n,k;
    cin >> n >> k;
    rep(i,k+1)dp[i] = -1;
    dp[0] = 1;
    rep(i,n){
        int a;
        cin >> a;
        for(int j = k+1;j >= 0;j--){
            if(dp[j] == 1){
                dp[j+a] = 1;
            }
        }
    }
    int ans = -1;
    rep(i,k+1){
        if(dp[i] != -1){
            ans = i;
        }
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}
0