結果

問題 No.527 ナップサック容量問題
ユーザー sima.tettekesima.tetteke
提出日時 2019-09-22 21:09:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,403 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 168,004 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 07:23:39
合計ジャッジ時間 2,871 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 6 ms
4,348 KB
testcase_06 AC 11 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 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
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 3 ms
4,348 KB
testcase_31 AC 6 ms
4,348 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 3 ms
4,348 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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 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 = 100005; 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(vec[i].first == j){
                if(dp[j] == 1145141919){
                    dp[j] = vec[i].second;
                }else{
                    dp[j] = min(dp[j], vec[i].second);
                    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;
        if(dp[V+1] == 1145141919){
            cout << "inf" << endl;
        }else{
            cout << dp[V+1] - 1 << endl;
        }
    }

    

} 
0