結果
| 問題 |
No.527 ナップサック容量問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-25 18:03:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 844 bytes |
| コンパイル時間 | 659 ms |
| コンパイル使用メモリ | 86,436 KB |
| 最終ジャッジ日時 | 2024-11-14 21:35:49 |
| 合計ジャッジ時間 | 1,124 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:23:24: error: variable 'std::array<int, 100001> a' has initializer but incomplete type
23 | array<int, 100001> a{};
| ^
ソースコード
#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
int main() {
int n;
cin >> n;
array<int, 100001> a{};
for (int i = 0; i < n; ++i) {
int v, w; cin >> v >> w;
for (int j = 100000; j >= w; --j) {
a[j] = max(a[j], a[j-w]+v);
}
}
int V; cin >> V;
cout << max(1, static_cast<int>(lower_bound(a.begin(),a.end(), V) - a.begin())) << "\n";
if(a.back() == V) puts("inf");
else cout << upper_bound(a.begin(),a.end(), V) - a.begin()-1 << "\n";
return 0;
}