結果

問題 No.527 ナップサック容量問題
ユーザー んんんんんん
提出日時 2023-01-08 16:25:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 885 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 201,328 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-22 02:36:15
合計ジャッジ時間 6,297 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 3 ms
4,384 KB
testcase_02 AC 12 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 154 ms
4,380 KB
testcase_06 AC 381 ms
4,376 KB
testcase_07 AC 55 ms
4,376 KB
testcase_08 AC 128 ms
4,376 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 167 ms
4,376 KB
testcase_11 AC 240 ms
4,436 KB
testcase_12 AC 166 ms
4,388 KB
testcase_13 AC 398 ms
4,380 KB
testcase_14 AC 27 ms
4,376 KB
testcase_15 AC 32 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 47 ms
4,380 KB
testcase_18 AC 61 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 15 ms
4,376 KB
testcase_21 AC 41 ms
4,384 KB
testcase_22 AC 27 ms
4,376 KB
testcase_23 AC 39 ms
4,384 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 26 ms
4,380 KB
testcase_26 AC 24 ms
4,376 KB
testcase_27 AC 24 ms
4,376 KB
testcase_28 AC 21 ms
4,380 KB
testcase_29 AC 39 ms
4,376 KB
testcase_30 AC 34 ms
4,500 KB
testcase_31 AC 18 ms
4,388 KB
testcase_32 AC 22 ms
4,388 KB
testcase_33 AC 19 ms
4,380 KB
testcase_34 AC 23 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 3 ms
4,384 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int N, V;
vector<int> v, w;
vector<int> dp;

int ns(int W) {
    dp.assign(W+1, -1);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = W; j >= 0; j--) {
            if (j - w[i] >= 0) {
                dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
            }
        }
    }
    return dp[W];
}

int main() {
    cin >> N;
    v.resize(N); w.resize(N);
    for (int i = 0; i < N; i++) cin >> v[i] >> w[i];
    cin >> V;

    int ok = 100000, ng = 0;
    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;
        if (ns(mid) < V-1) ng = mid;
        else ok = mid;
    }
    cout << ok << endl;
    ok = 1, ng = 100002;
    while (ng - ok > 1) {
        int mid = (ok + ng) / 2;
        if (ns(mid) > V) ng = mid;
        else ok = mid;
    }
    if (ok == 100001) cout << "inf" << endl;
    else cout << ok << endl;
}
0