結果

問題 No.527 ナップサック容量問題
ユーザー mint6421mint6421
提出日時 2019-07-07 01:31:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,266 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 165,092 KB
実行使用メモリ 82,588 KB
最終ジャッジ日時 2024-04-09 21:15:18
合計ジャッジ時間 4,289 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 4 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 37 ms
35,072 KB
testcase_06 AC 79 ms
70,656 KB
testcase_07 AC 62 ms
57,344 KB
testcase_08 AC 30 ms
30,464 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 82 ms
71,424 KB
testcase_11 AC 58 ms
50,816 KB
testcase_12 AC 39 ms
37,504 KB
testcase_13 AC 81 ms
73,088 KB
testcase_14 AC 31 ms
27,904 KB
testcase_15 AC 47 ms
43,268 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 39 ms
35,968 KB
testcase_18 AC 43 ms
40,704 KB
testcase_19 AC 5 ms
7,552 KB
testcase_20 AC 30 ms
29,780 KB
testcase_21 AC 93 ms
82,588 KB
testcase_22 AC 62 ms
55,552 KB
testcase_23 AC 90 ms
80,128 KB
testcase_24 AC 18 ms
18,688 KB
testcase_25 AC 61 ms
54,016 KB
testcase_26 AC 53 ms
48,512 KB
testcase_27 AC 54 ms
49,480 KB
testcase_28 AC 45 ms
43,244 KB
testcase_29 AC 93 ms
81,664 KB
testcase_30 AC 10 ms
10,624 KB
testcase_31 AC 39 ms
36,480 KB
testcase_32 AC 48 ms
44,544 KB
testcase_33 AC 40 ms
38,016 KB
testcase_34 AC 50 ms
45,952 KB
testcase_35 AC 50 ms
46,080 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 37 ms
35,344 KB
testcase_38 AC 47 ms
43,776 KB
testcase_39 AC 43 ms
40,576 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;
int dp[110][110000];
P s[110];
int v;

main(){
  cin>>n;
  rep(i,n){
    cin>>s[i].F>>s[i].S;
  }
  cin>>v;

  FOR(j,s[0].S,100010){
    dp[0][j]=s[0].F;
  }


  

  FOR(i,1,n){
    rep(j,100010){
      dp[i][j]=max(dp[i][j],dp[i-1][j]);
      dp[i][j+s[i].S]=max(dp[i][j+s[i].S],dp[i-1][j]+s[i].F);
    }
  }

  int l=-1,r=-1;
  FOR(j,1,100010){
    if(dp[n-1][j]==v){
      l=j;
      while(j<100010&&dp[n-1][l]==dp[n-1][j]) j++;
      r=j;
      r--;
      break;
    }
  }

  cout<<l<<endl;
  if(r>100000){
    cout<<"inf"<<endl;
  }else{
    cout<<r<<endl;
  }

}

0