結果

問題 No.527 ナップサック容量問題
ユーザー masaktmasakt
提出日時 2017-06-09 23:25:24
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,795 bytes
コンパイル時間 1,353 ms
コンパイル使用メモリ 74,236 KB
実行使用メモリ 43,192 KB
最終ジャッジ日時 2023-10-24 02:14:18
合計ジャッジ時間 2,801 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
43,152 KB
testcase_01 AC 12 ms
43,152 KB
testcase_02 AC 12 ms
43,156 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 14 ms
43,156 KB
testcase_06 AC 19 ms
43,156 KB
testcase_07 WA -
testcase_08 AC 13 ms
43,156 KB
testcase_09 AC 11 ms
43,156 KB
testcase_10 WA -
testcase_11 AC 15 ms
43,156 KB
testcase_12 AC 13 ms
43,156 KB
testcase_13 AC 17 ms
43,156 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 12 ms
43,156 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>

#define MAX_N 100000
using namespace std;

int n;
int w[100 + 1], v[100 + 1];
int dp[100 + 1][MAX_N + 1];
int V;

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        memset(dp, -1, sizeof(dp));
        in >> n;

        int m = 0;
        for (int i = 0; i < n; i++)
        {
            in >> v[i] >> w[i];
            m += w[i];
        }
        in >> V;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j <= V; j++)
            {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                if (j + v[i] <= V)
                {
                    dp[i + 1][j + v[i]] = max(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
                }
            }
        }
        int amin = 1;
        int amax = 3;
        if (dp[n][V] != -1)
        {
            amin += dp[n][V];
            amax += dp[n][V];
            if (m <= amin)
            {
                out << amin << endl;
                out << "inf" << endl;
            }
            else
            {
                out << amin << endl;
                out << amax << endl;
            }
        }
        else
        {
            out << amin << endl;
            out << amax << endl;
        }

    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}
0