結果
問題 | No.527 ナップサック容量問題 |
ユーザー | saxofone111 |
提出日時 | 2021-04-16 12:25:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,810 bytes |
コンパイル時間 | 2,187 ms |
コンパイル使用メモリ | 207,660 KB |
実行使用メモリ | 140,040 KB |
最終ジャッジ日時 | 2023-09-15 10:17:45 |
合計ジャッジ時間 | 7,863 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
11,616 KB |
testcase_01 | AC | 21 ms
7,740 KB |
testcase_02 | AC | 149 ms
9,424 KB |
testcase_03 | AC | 22 ms
7,720 KB |
testcase_04 | AC | 13 ms
5,408 KB |
testcase_05 | AC | 1,339 ms
68,824 KB |
testcase_06 | TLE | - |
testcase_07 | AC | 310 ms
57,912 KB |
testcase_08 | AC | 1,142 ms
59,768 KB |
testcase_09 | AC | 122 ms
8,056 KB |
testcase_10 | AC | 838 ms
72,180 KB |
testcase_11 | AC | 1,988 ms
100,648 KB |
testcase_12 | AC | 1,423 ms
74,092 KB |
testcase_13 | TLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for(ll i=0; i < (n); i++) #define rrep(i, n) for(ll i=(n)-1; i >=0; i--) #define ALL(v) v.begin(),v.end() #define rALL(v) v.rbegin(),v.rend() #define FOR(i, j, k) for(ll i=j;i<k;i++) #define debug_print(var) cerr << #var << "=" << var <<endl; #define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" " #define fi first #define se second using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge{ll x, c;}; /************************************** ** A main function starts from here ** ***************************************/ int main(){ ll N; cin >> N; llvec v(N); llvec w(N); rep(i, N){ cin >> v[i] >> w[i]; } ll ok = 200000; ll ng = 0; ll V; cin >> V; while(abs(ok-ng)>1){ ll m = (ok+ng) / 2; vector<llvec> dp(N+1, llvec(m+1, 0)); rep(i, N){ rep(j, m+1){ dp[i+1][j] = max(dp[i][j], dp[i+1][j]); if(j+w[i]<=m){ dp[i+1][j+w[i]] = max(dp[i][j] + v[i], dp[i+1][j+w[i]]); } } } sort(ALL(dp[N])); if(dp[N].back()>=V){ ok = m; }else{ ng = m; } } ll ans1 = ok; ok = 200000; ng = 0; while(abs(ok-ng)>1){ ll m = (ok+ng) / 2; vector<llvec> dp(N+1, llvec(m+1, 0)); rep(i, N){ rep(j, m+1){ dp[i+1][j] = max(dp[i][j], dp[i+1][j]); if(j+w[i]<=m){ dp[i+1][j+w[i]] = max(dp[i][j] + v[i], dp[i+1][j+w[i]]); } } } sort(ALL(dp[N])); if(dp[N].back()>V){ ok = m; }else{ ng = m; } } ll ans2 = ng; if(ans2<=1e5){ cout << ans1 << endl << ans2 << endl; }else{ cout << ans1 << endl << "inf" << endl; } return 0; }