結果

問題 No.527 ナップサック容量問題
ユーザー tottoripapertottoripaper
提出日時 2018-03-13 18:25:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 1,580 ms
コンパイル使用メモリ 167,124 KB
実行使用メモリ 46,464 KB
最終ジャッジ日時 2024-05-02 02:15:13
合計ジャッジ時間 4,501 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
46,336 KB
testcase_01 AC 32 ms
46,464 KB
testcase_02 AC 32 ms
46,336 KB
testcase_03 AC 33 ms
46,336 KB
testcase_04 AC 32 ms
46,336 KB
testcase_05 AC 42 ms
46,336 KB
testcase_06 AC 53 ms
46,464 KB
testcase_07 AC 50 ms
46,464 KB
testcase_08 AC 41 ms
46,464 KB
testcase_09 AC 31 ms
46,464 KB
testcase_10 AC 54 ms
46,464 KB
testcase_11 AC 47 ms
46,464 KB
testcase_12 AC 43 ms
46,464 KB
testcase_13 AC 55 ms
46,336 KB
testcase_14 AC 40 ms
46,464 KB
testcase_15 AC 44 ms
46,464 KB
testcase_16 AC 33 ms
46,336 KB
testcase_17 AC 42 ms
46,464 KB
testcase_18 AC 43 ms
46,336 KB
testcase_19 AC 33 ms
46,464 KB
testcase_20 AC 40 ms
46,336 KB
testcase_21 AC 58 ms
46,336 KB
testcase_22 AC 49 ms
46,464 KB
testcase_23 AC 57 ms
46,336 KB
testcase_24 AC 36 ms
46,336 KB
testcase_25 AC 48 ms
46,464 KB
testcase_26 AC 46 ms
46,336 KB
testcase_27 AC 47 ms
46,336 KB
testcase_28 AC 44 ms
46,464 KB
testcase_29 AC 57 ms
46,464 KB
testcase_30 AC 35 ms
46,336 KB
testcase_31 AC 43 ms
46,208 KB
testcase_32 AC 45 ms
46,464 KB
testcase_33 AC 43 ms
46,464 KB
testcase_34 AC 46 ms
46,336 KB
testcase_35 AC 46 ms
46,336 KB
testcase_36 AC 32 ms
46,336 KB
testcase_37 AC 42 ms
46,336 KB
testcase_38 AC 45 ms
46,336 KB
testcase_39 AC 44 ms
46,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, V;
int vs[110], _ws[110];
int dp[110][100100];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> vs[i] >> _ws[i];
    }

    std::cin >> V;

    fill(&dp[0][0], &dp[0][0]+110*100100, 1001001001);
    dp[0][0] = 0;

    for(int i=0;i<N;++i){
        for(int j=0;j<=100000;++j){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            if(j + vs[i] <= 100000){
                dp[i+1][j+vs[i]] = min(dp[i+1][j+vs[i]], dp[i][j] + _ws[i]);
            }
        }
    }

    int mn = max(dp[N][V], 1),
        mx = 1001001001;

    for(int i=V+1;i<=100000;++i){
        if(dp[N][i] == 1001001001){continue;}
        mx = min(mx, dp[N][i] - 1);
    }
    
    std::cout << mn << std::endl;
    if(mx == 1001001001){
        std::cout << "inf" << std::endl;
    }else{
        std::cout << mx << std::endl;
    }
}
0