結果

問題 No.527 ナップサック容量問題
ユーザー zekezeke
提出日時 2019-12-08 14:35:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,174 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 100,040 KB
実行使用メモリ 122,852 KB
最終ジャッジ日時 2023-08-28 21:29:06
合計ジャッジ時間 5,342 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
8,784 KB
testcase_01 AC 8 ms
10,100 KB
testcase_02 AC 6 ms
7,864 KB
testcase_03 AC 8 ms
10,056 KB
testcase_04 AC 5 ms
6,540 KB
testcase_05 AC 45 ms
52,148 KB
testcase_06 AC 93 ms
104,852 KB
testcase_07 WA -
testcase_08 AC 38 ms
45,244 KB
testcase_09 AC 5 ms
6,412 KB
testcase_10 WA -
testcase_11 AC 66 ms
75,548 KB
testcase_12 AC 48 ms
55,936 KB
testcase_13 AC 95 ms
108,576 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 AC 71 ms
80,304 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 56 ms
63,920 KB
testcase_29 WA -
testcase_30 AC 13 ms
15,900 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 7 ms
8,760 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int,int>> vec(n);
    rep(i, n) cin >> vec[i].F >> vec[i].S;
    vector<vector<int>> dp(n + 1, vector<int>(3*1e5, 1e9));
    dp[0][0] = 0;
    rep3(i, 1, n + 1)
    {
        rep(j, 1e5 + 1)
        {
            chmin(dp[i][j], dp[i - 1][j]);
            chmin(dp[i][vec[i - 1].S + j], dp[i - 1][j] + vec[i - 1].F);
        }
    }
    ll value;
    cin >> value;
    ll pre = 0;
    rep(i,1e5){
        if(dp[n][i]==1e9){
            dp[n][i] = pre;
        }else{
            pre = dp[n][i];
        }
    }
    
    
    cout << max(lower_bound(all(dp[n]), value)-dp[n].begin(),(long)1) << endl;
    if(upper_bound(all(dp[n]), value)-dp[n].begin()-1==99999){
        cout<<"inf"<<endl;
        return 0;
    }
    cout << upper_bound(all(dp[n]), value)-dp[n].begin()-1 << endl;
}
0