結果

問題 No.527 ナップサック容量問題
ユーザー zekezeke
提出日時 2019-12-08 14:33:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,127 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 101,148 KB
実行使用メモリ 800,308 KB
最終ジャッジ日時 2023-08-28 21:26:03
合計ジャッジ時間 10,740 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
42,212 KB
testcase_01 AC 24 ms
49,880 KB
testcase_02 AC 16 ms
34,152 KB
testcase_03 AC 23 ms
49,868 KB
testcase_04 AC 12 ms
26,428 KB
testcase_05 AC 190 ms
331,200 KB
testcase_06 MLE -
testcase_07 MLE -
testcase_08 AC 141 ms
284,284 KB
testcase_09 AC 13 ms
26,452 KB
testcase_10 MLE -
testcase_11 AC 229 ms
487,628 KB
testcase_12 AC 168 ms
354,664 KB
testcase_13 MLE -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 WA -
testcase_25 MLE -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 201 ms
409,280 KB
testcase_29 MLE -
testcase_30 AC 40 ms
89,040 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 19 ms
42,096 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);
    ll n;
    cin >> n;
    VP vec(n);
    rep(i, n) cin >> vec[i].F >> vec[i].S;
    VV dp(n + 1, V(1e6, 1e18));
    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]==1e18){
            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