結果

問題 No.527 ナップサック容量問題
ユーザー RyuRyu
提出日時 2018-01-11 21:50:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 75,572 KB
実行使用メモリ 42,384 KB
最終ジャッジ日時 2023-08-25 04:05:47
合計ジャッジ時間 3,208 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,808 KB
testcase_01 AC 5 ms
4,916 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 5 ms
4,920 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 25 ms
18,952 KB
testcase_06 AC 49 ms
36,632 KB
testcase_07 AC 40 ms
29,956 KB
testcase_08 AC 21 ms
16,716 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 49 ms
36,928 KB
testcase_11 AC 35 ms
26,780 KB
testcase_12 AC 26 ms
20,336 KB
testcase_13 AC 50 ms
37,916 KB
testcase_14 AC 19 ms
15,720 KB
testcase_15 AC 30 ms
23,140 KB
testcase_16 AC 5 ms
4,880 KB
testcase_17 AC 26 ms
19,672 KB
testcase_18 AC 28 ms
21,708 KB
testcase_19 AC 5 ms
5,380 KB
testcase_20 AC 21 ms
16,212 KB
testcase_21 AC 57 ms
42,384 KB
testcase_22 AC 38 ms
29,120 KB
testcase_23 AC 56 ms
41,244 KB
testcase_24 AC 12 ms
10,756 KB
testcase_25 AC 37 ms
28,324 KB
testcase_26 AC 34 ms
25,732 KB
testcase_27 AC 34 ms
26,072 KB
testcase_28 AC 29 ms
23,068 KB
testcase_29 AC 57 ms
41,996 KB
testcase_30 AC 7 ms
6,904 KB
testcase_31 AC 26 ms
19,868 KB
testcase_32 AC 32 ms
23,644 KB
testcase_33 AC 27 ms
20,588 KB
testcase_34 AC 32 ms
24,452 KB
testcase_35 AC 33 ms
24,496 KB
testcase_36 AC 4 ms
4,632 KB
testcase_37 AC 25 ms
19,028 KB
testcase_38 AC 31 ms
23,312 KB
testcase_39 AC 29 ms
21,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#define rep(i, n) for (int i = 0; i < (n); i++)

using ll = long long int;
using namespace std;
const int MAX = 100000;

int N, V;
int w[1010], v[1010], dp[110][100010];
vector<int> vec;

int main()
{
    cin >> N;
    rep(i, N)
            cin >>
        v[i] >> w[i];
    cin >> V;

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <= MAX; j++)
        {
            if (j + w[i] <= MAX)
            {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
            }
        }
    }

    int mi = 1000000000;
    int ma = -1;
    for (int i = 1; i < 100001; i++)
    {
        if (dp[N][i] == V)
        {
            mi = min(mi, i);
            ma = max(ma, i);
        }
    }
    cout << mi << endl;
    if (ma == 100000)
        cout << "inf" << endl;
    else
        cout << ma << endl;
}
0