結果

問題 No.527 ナップサック容量問題
ユーザー kappybarkappybar
提出日時 2020-05-04 13:24:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 1,467 ms
コンパイル使用メモリ 171,692 KB
実行使用メモリ 42,804 KB
最終ジャッジ日時 2023-09-06 12:03:32
合計ジャッジ時間 3,818 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,080 KB
testcase_01 AC 4 ms
5,460 KB
testcase_02 AC 3 ms
4,724 KB
testcase_03 AC 4 ms
5,460 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 20 ms
19,392 KB
testcase_06 AC 39 ms
37,136 KB
testcase_07 AC 31 ms
30,444 KB
testcase_08 AC 17 ms
17,012 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 40 ms
37,560 KB
testcase_11 AC 28 ms
27,412 KB
testcase_12 AC 20 ms
20,624 KB
testcase_13 AC 40 ms
38,356 KB
testcase_14 AC 16 ms
15,872 KB
testcase_15 AC 24 ms
23,304 KB
testcase_16 AC 4 ms
5,344 KB
testcase_17 AC 20 ms
19,888 KB
testcase_18 AC 23 ms
22,256 KB
testcase_19 AC 4 ms
5,628 KB
testcase_20 AC 17 ms
16,660 KB
testcase_21 AC 45 ms
42,804 KB
testcase_22 AC 31 ms
29,792 KB
testcase_23 AC 45 ms
41,796 KB
testcase_24 AC 11 ms
11,316 KB
testcase_25 AC 29 ms
28,952 KB
testcase_26 AC 27 ms
26,216 KB
testcase_27 AC 27 ms
26,436 KB
testcase_28 AC 24 ms
23,348 KB
testcase_29 AC 45 ms
42,584 KB
testcase_30 AC 7 ms
7,240 KB
testcase_31 AC 21 ms
20,288 KB
testcase_32 AC 25 ms
24,056 KB
testcase_33 AC 23 ms
20,940 KB
testcase_34 AC 27 ms
24,900 KB
testcase_35 AC 26 ms
24,884 KB
testcase_36 AC 3 ms
4,844 KB
testcase_37 AC 20 ms
19,304 KB
testcase_38 AC 25 ms
23,980 KB
testcase_39 AC 23 ms
22,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int W = 100005;

int main(){
    int n;
    cin >> n;
    vector<P> wv(n);
    rep(i,n){
        cin >> wv[i].second >> wv[i].first;
    }
    int V;cin >> V;
    vector<vector<int>> dp(n+1,vector<int>(W,0));

    for(int i=1;i<=n;i++){
        rep(j,W){
            if(j - wv[i-1].first >=0){
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-wv[i-1].first] + wv[i-1].second);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    int mn = INF;
    int mx = 0;
    for(int j=1;j<W;j++){
        if(dp[n][j] == V){
            mn = min(mn,j);
            mx = max(mx,j);
        }
    }

    if(mx == W-1) mx = -1;
    cout << mn << endl;
    if(mx ==-1) cout << "inf" << endl;
    else cout << mx << endl;
    return 0;
}
0