結果

問題 No.527 ナップサック容量問題
ユーザー algon_320algon_320
提出日時 2017-06-17 13:54:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 167,900 KB
実行使用メモリ 82,396 KB
最終ジャッジ日時 2024-04-08 17:29:35
合計ジャッジ時間 4,776 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
82,396 KB
testcase_01 AC 26 ms
82,396 KB
testcase_02 AC 25 ms
82,396 KB
testcase_03 AC 24 ms
82,396 KB
testcase_04 AC 24 ms
82,396 KB
testcase_05 AC 29 ms
82,396 KB
testcase_06 AC 35 ms
82,396 KB
testcase_07 AC 33 ms
82,396 KB
testcase_08 AC 28 ms
82,396 KB
testcase_09 AC 24 ms
82,396 KB
testcase_10 AC 36 ms
82,396 KB
testcase_11 AC 32 ms
82,396 KB
testcase_12 AC 30 ms
82,396 KB
testcase_13 AC 36 ms
82,396 KB
testcase_14 AC 28 ms
82,396 KB
testcase_15 AC 31 ms
82,396 KB
testcase_16 AC 24 ms
82,396 KB
testcase_17 AC 29 ms
82,396 KB
testcase_18 AC 31 ms
82,396 KB
testcase_19 AC 25 ms
82,396 KB
testcase_20 AC 28 ms
82,396 KB
testcase_21 AC 39 ms
82,396 KB
testcase_22 AC 33 ms
82,396 KB
testcase_23 AC 37 ms
82,396 KB
testcase_24 AC 26 ms
82,396 KB
testcase_25 AC 32 ms
82,396 KB
testcase_26 AC 32 ms
82,396 KB
testcase_27 AC 32 ms
82,396 KB
testcase_28 AC 30 ms
82,396 KB
testcase_29 AC 39 ms
82,396 KB
testcase_30 AC 25 ms
82,396 KB
testcase_31 AC 29 ms
82,396 KB
testcase_32 AC 31 ms
82,396 KB
testcase_33 AC 30 ms
82,396 KB
testcase_34 AC 31 ms
82,396 KB
testcase_35 AC 30 ms
82,396 KB
testcase_36 AC 24 ms
82,396 KB
testcase_37 AC 28 ms
82,396 KB
testcase_38 AC 29 ms
82,396 KB
testcase_39 AC 29 ms
82,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1001001001;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

int dp[101][100001];
int N,v[101],w[101],V;
signed main() {
    for(int i=0; i<101; i++) {
        for(int j=0; j<100001; j++) {
            dp[i][j]=INF;
        }
    }
    cin>>N;
    for(int i=0; i<N; i++) {
        cin>>v[i]>>w[i];
    }
    cin>>V;

    dp[0][0]=0;
    dp[0][v[0]]=w[0];
    for(int i=0; i<N-1; i++) {
        for(int j=0; j<100001; j++) {
            if(dp[i][j]!=INF) {
                if(j+v[i+1]<100001) chmin(dp[i+1][j+v[i+1]],dp[i][j]+w[i+1]);
                chmin(dp[i+1][j],dp[i][j]);
            }
        }
    }

    int min=dp[N-1][V];
    if(min==0) min=1;
    cout<<min<<endl;

    if(V==accumulate(v,v+N,0ll)) {
        cout<<"inf"<<endl;
        return 0;
    }

    int t=INF;
    for(int i=V+1; i<100001; i++) {
        chmin(t,dp[N-1][i]);
    }
    cout<<t-1<<endl;
}
0