結果

問題 No.527 ナップサック容量問題
ユーザー ukuku09ukuku09
提出日時 2017-06-09 23:18:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,167 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 162,624 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 01:50:24
合計ジャッジ時間 3,553 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,372 KB
testcase_01 AC 3 ms
4,372 KB
testcase_02 AC 3 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 6 ms
4,372 KB
testcase_06 AC 10 ms
4,372 KB
testcase_07 AC 9 ms
4,372 KB
testcase_08 AC 6 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 11 ms
4,372 KB
testcase_11 AC 8 ms
4,372 KB
testcase_12 AC 7 ms
4,372 KB
testcase_13 AC 11 ms
4,372 KB
testcase_14 AC 5 ms
4,372 KB
testcase_15 AC 7 ms
4,372 KB
testcase_16 AC 3 ms
4,372 KB
testcase_17 AC 6 ms
4,372 KB
testcase_18 AC 7 ms
4,372 KB
testcase_19 AC 3 ms
4,372 KB
testcase_20 AC 6 ms
4,372 KB
testcase_21 AC 12 ms
4,372 KB
testcase_22 AC 8 ms
4,372 KB
testcase_23 AC 11 ms
4,372 KB
testcase_24 AC 4 ms
4,372 KB
testcase_25 AC 8 ms
4,372 KB
testcase_26 AC 8 ms
4,372 KB
testcase_27 AC 8 ms
4,372 KB
testcase_28 AC 7 ms
4,372 KB
testcase_29 AC 12 ms
4,372 KB
testcase_30 AC 4 ms
4,372 KB
testcase_31 AC 6 ms
4,372 KB
testcase_32 AC 7 ms
4,372 KB
testcase_33 AC 7 ms
4,372 KB
testcase_34 AC 8 ms
4,372 KB
testcase_35 AC 8 ms
4,372 KB
testcase_36 AC 3 ms
4,372 KB
testcase_37 AC 7 ms
4,372 KB
testcase_38 AC 7 ms
4,372 KB
testcase_39 AC 7 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int dp[100100];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, V;
  cin >> N;
  vint v(N), w(N);
  rep(i, N) cin >> v[i] >> w[i];
  cin >> V;
  dp[100001] = V;
  rep(i, N) {
    for(int j = 100000; j >= w[i]; j--) {
      chmax(dp[j], dp[j-w[i]]+v[i]);
    }
  }
  int mn = 1;
  while(dp[mn] != V) mn++;
  int mx = mn;
  while(dp[mx+1] == dp[mn]) mx++;

  if(mn == 100001) {
    cout << 1 << endl << *min_element(all(w))-1 << endl;
  } else if(mx == 100001) {
    cout << mn << endl << "inf" << endl;
  } else {
    cout << mn << endl << mx << endl;
  }

  return 0;
}
0