結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 8 ms
4,348 KB
testcase_06 AC 13 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 AC 13 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 10 ms
4,348 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 8 ms
4,348 KB
testcase_29 WA -
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 7 ms
4,348 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 8 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 7 ms
4,348 KB
testcase_38 AC 8 ms
4,348 KB
testcase_39 AC 8 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;
    //cout << dp[100004] << endl;

    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[j] != 1145141919){
                //cout << dp[j]  << " " << j + vec[i].first << endl;
                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;
        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