結果

問題 No.527 ナップサック容量問題
ユーザー koprickykopricky
提出日時 2017-07-16 04:42:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,346 bytes
コンパイル時間 1,278 ms
コンパイル使用メモリ 159,636 KB
実行使用メモリ 42,496 KB
最終ジャッジ日時 2024-04-16 22:09:25
合計ジャッジ時間 3,516 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 26 ms
19,072 KB
testcase_06 AC 53 ms
36,608 KB
testcase_07 AC 42 ms
29,952 KB
testcase_08 AC 22 ms
16,768 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 53 ms
37,120 KB
testcase_11 AC 37 ms
26,752 KB
testcase_12 AC 28 ms
20,224 KB
testcase_13 AC 54 ms
37,888 KB
testcase_14 AC 21 ms
15,488 KB
testcase_15 AC 32 ms
23,040 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 27 ms
19,328 KB
testcase_18 AC 30 ms
21,760 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 21 ms
16,128 KB
testcase_21 AC 60 ms
42,496 KB
testcase_22 AC 41 ms
29,312 KB
testcase_23 AC 59 ms
41,344 KB
testcase_24 AC 13 ms
10,752 KB
testcase_25 AC 40 ms
28,416 KB
testcase_26 AC 36 ms
25,728 KB
testcase_27 AC 36 ms
25,984 KB
testcase_28 AC 32 ms
23,040 KB
testcase_29 AC 60 ms
42,112 KB
testcase_30 AC 8 ms
7,040 KB
testcase_31 AC 27 ms
19,584 KB
testcase_32 AC 32 ms
23,680 KB
testcase_33 AC 28 ms
20,608 KB
testcase_34 AC 34 ms
24,448 KB
testcase_35 AC 34 ms
24,448 KB
testcase_36 AC 4 ms
5,376 KB
testcase_37 AC 26 ms
18,944 KB
testcase_38 AC 32 ms
23,424 KB
testcase_39 AC 30 ms
21,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 101;
const int MAX_W = 100002;

int dp[MAX_N][MAX_W];

int main()
{
    int n;
    cin >> n;
    vector<int> v(n),w(n);
    rep(i,n){
        cin >> v[i] >> w[i];
    }
    rep(i,n){
        rep(j,MAX_W-1){
            if(j - w[i] >= 0){
                dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]] + v[i]);
            }
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
        }
    }
    int mn = INF;
    int mx = -1;
    int V;
    cin >> V;
    rep(i,MAX_W-1){
        if(dp[n][i] == V){
            mn = min(mn,i);
            mx = max(mx,i);
        }
    }
    if(mx == MAX_W-2){
        cout << max(mn,1) << endl;
        cout << "inf\n";
    }else{
        cout << max(mn,1) << endl;
        cout << mx << endl;
    }
    return 0;
}
0