結果

問題 No.527 ナップサック容量問題
ユーザー KiYugadgeterKiYugadgeter
提出日時 2019-04-09 09:46:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,438 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 64,888 KB
実行使用メモリ 80,664 KB
最終ジャッジ日時 2023-09-14 15:49:10
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
5,584 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
5,336 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 17 ms
55,604 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 21 ms
70,260 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 7 ms
26,324 KB
testcase_15 AC 12 ms
41,036 KB
testcase_16 AC 2 ms
5,304 KB
testcase_17 AC 9 ms
34,332 KB
testcase_18 AC 10 ms
39,004 KB
testcase_19 AC 2 ms
5,344 KB
testcase_20 AC 8 ms
28,180 KB
testcase_21 AC 25 ms
80,664 KB
testcase_22 AC 15 ms
53,628 KB
testcase_23 AC 22 ms
78,672 KB
testcase_24 AC 5 ms
17,924 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 14 ms
47,420 KB
testcase_28 WA -
testcase_29 AC 24 ms
80,212 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 8 ms
34,008 KB
testcase_32 AC 10 ms
42,180 KB
testcase_33 AC 9 ms
36,048 KB
testcase_34 AC 10 ms
44,244 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:53:33: 警告: ‘num_payload’ may be used uninitialized [-Wmaybe-uninitialized]
   53 |     for (ull r = num_payload; r <= n; r++) {
      |                               ~~^~~~
main.cpp:11:9: 備考: ‘num_payload’ はここで定義されています
   11 |     ull num_payload;
      |         ^~~~~~~~~~~

ソースコード

diff #

#include <iostream>

using ull = long long int;

ull n;
ull v;
ull max_w = 100000;
ull min_cap = -1;
ull equal_weight = -1;
int main() {
    ull num_payload;
    ull k = 0;
    ull x = 0;
    std::cin >> n;
    ull dp[n+1][100001];
    ull values[n];
    ull weights[n];
    for (ull i = 0; i < n; i++) {
        std::cin >> values[i] >> weights[i];
        k += values[i];
        x += weights[i];
    }
    std::cin >> v;
    if (v >= k) {
        std::cout << x << std::endl;
        std::cout << "inf" << std::endl;
        return 0;
    }
    
    for (ull i = 0; i <= x; i++) {
        dp[0][i] = 0;
    }
    for (ull i = 1; i <= n; i++) {
        for (ull p = 0; p <= x; p++) {
            if (p >= weights[i-1]) {
                dp[i][p] = std::max(dp[i-1][p-weights[i-1]] + values[i-1], dp[i-1][p]);
                if (dp[i][p] == v) {
                    if (min_cap == -1) {
                        min_cap = p;
                        num_payload = i;
                    }
                }
            }
            else {
                dp[i][p] = dp[i-1][p];
            }
        }
    }
    if (min_cap == -1) {
        min_cap = 1;
        num_payload = 1;
    }
    for (ull r = num_payload; r <= n; r++) {
        for (ull i = min_cap; i <=x; i++) {
            if (dp[r][i] > v) {
                std::cout << min_cap << std::endl << i - 1 << std::endl;
                return 0;
            }
        }
    }
}
0