結果
| 問題 | No.527 ナップサック容量問題 |
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-04 23:43:05 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 714 bytes |
| 記録 | |
| コンパイル時間 | 1,308 ms |
| コンパイル使用メモリ | 214,752 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-09 08:26:43 |
| 合計ジャッジ時間 | 3,005 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using lubl=long double;
void cmx(lint&x,lint y){if(x<y)x=y;}
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint lim=100'004;
std::vector<lint>dp(lim);
lint n;std::cin>>n;
while(n--){
lint v,w;std::cin>>v>>w;
for(lint i=lim-1-w;i>=0;i--){
cmx(dp.at(i+w),dp.at(i)+v);
}
}
lint V;std::cin>>V;
auto&&[lb,rb]=std::equal_range(ALL(dp),V);
std::cout<<std::max(1ll,lint(lb-dp.begin()))<<'\n';
std::cout<<(rb==dp.end()?"inf":std::to_string(rb-dp.begin()-1))<<'\n';
}
ngtkana