結果

問題 No.527 ナップサック容量問題
ユーザー RyuRyu
提出日時 2018-01-11 21:02:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 956 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 74,196 KB
実行使用メモリ 46,588 KB
最終ジャッジ日時 2023-08-25 04:03:25
合計ジャッジ時間 3,290 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
46,372 KB
testcase_01 WA -
testcase_02 AC 15 ms
46,316 KB
testcase_03 WA -
testcase_04 AC 15 ms
46,424 KB
testcase_05 AC 20 ms
46,316 KB
testcase_06 AC 27 ms
46,312 KB
testcase_07 WA -
testcase_08 AC 20 ms
46,320 KB
testcase_09 AC 15 ms
46,280 KB
testcase_10 WA -
testcase_11 AC 23 ms
46,312 KB
testcase_12 AC 21 ms
46,584 KB
testcase_13 AC 27 ms
46,372 KB
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 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 17 ms
46,320 KB
testcase_31 AC 21 ms
46,296 KB
testcase_32 AC 23 ms
46,292 KB
testcase_33 AC 21 ms
46,508 KB
testcase_34 AC 22 ms
46,284 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

int N, V;
int v[1010], w[1010];
int dp[110][100010];

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

    cin >> V;

    memset(dp, 0, sizeof(dp));

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 100002; j++)
        {
            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 = 100001;
    int ma = -1;

    for(int i = 1; i < 100002; i++)
    {
        if(dp[N][i] == V)
        {
            mi = min(mi, i);
            ma = max(ma, i);
        }
    }

    cout << mi << endl;
    if(ma == 100001)
        cout << "inf" << endl;
    else 
        cout << ma << endl;
}
0