結果

問題 No.527 ナップサック容量問題
ユーザー sima.tettekesima.tetteke
提出日時 2019-09-22 22:56:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 165,076 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 07:26:54
合計ジャッジ時間 2,830 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 6 ms
4,348 KB
testcase_06 AC 10 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 10 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 3 ms
4,348 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 3 ms
4,348 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 8 ms
4,348 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 7 ms
4,348 KB
testcase_29 WA -
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 6 ms
4,348 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 7 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 6 ms
4,348 KB
testcase_38 AC 7 ms
4,348 KB
testcase_39 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll N;

int main(){
    
    ll N;
    cin >> N;

    vector<pair<ll, ll > > vec;

    ll max_w = 1145141919;
    ll min_w = 1145141919;
    for(ll i = 0; i < N; i++){
        ll v, w;
        cin >> v >> w;
        vec.push_back(make_pair(v, w));
        if(min_w > w){
            min_w = w;
        }
    }

    //sort(vec.begin(), vec.end());

    ll V;
    cin >> V;

    vector<ll > dp(100005, 1145141919);
    dp[0] = 0;
    
    for(ll i = 0; i < N; i++){
        for (ll j = 100004; j >= 0 ; j--){
            //cout << j << endl;
            //dp[j] = min(dp[j], dp[j-vec[i].first] + vec[i].second);
            if(dp[j] != 1145141919){
                dp[j + vec[i].first] = min(dp[j + vec[i].first], dp[j] + vec[i].second);
            }

        }  
    }

    if(dp[V] == 0){
        cout << "1" << endl;
        cout << min_w - 1  << endl;
    }else{
        cout << dp[V] << endl;
        for(ll i = V + 1; i < 100004; i++){
            if(dp[i] != 1145141919){
                max_w = dp[i];
                break;
            }
        }
        if(max_w == 1145141919){
            cout << "inf" << endl;
        }else{
            cout << max_w - 1 << endl;
        }
    }
} 
0