結果

問題 No.527 ナップサック容量問題
ユーザー HachimoriHachimori
提出日時 2017-06-09 22:47:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,077 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 58,932 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 22:17:24
合計ジャッジ時間 3,110 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 RE -
testcase_07 WA -
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 RE -
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 2 ms
4,348 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,348 KB
testcase_29 WA -
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2 ms
4,348 KB
testcase_35 RE -
testcase_36 AC 2 ms
4,348 KB
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<numeric>
#include<cstring>
using namespace std;
const int N_BURDEN = 105;
const int SUM_VALUE = 100005;


int N;
int value[N_BURDEN], weight[N_BURDEN];
int V;

void read() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> value[i] >> weight[i];
    }
    cin >> V;
}


void work() {
    int maxV[SUM_VALUE];
    memset(maxV, -1, sizeof(maxV));
    maxV[0] = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = V; j >= 0; --j) {
            if (maxV[j] != -1) {
                maxV[j + weight[i]] = max(maxV[j + weight[i]], maxV[j] + value[i]);
            }
        }
    }
    
    int idx;
    for (idx = 0;; ++idx) {
        if (maxV[idx] == V) {
            if (idx == 0) ++idx;
            cout << idx << endl;
            break;
        }
    }
    
    if (maxV[accumulate(weight, weight + N, 0)] == V) {
        cout << "inf" << endl;
    } else {
        ++idx;
        while (maxV[idx] == -1) ++idx;
        cout << idx - 1 << endl;
    }
}


int main() {
    read();
    work();
    return 0;
}
0