結果
| 問題 | No.527 ナップサック容量問題 |
| コンテスト | |
| ユーザー |
Nasatame
|
| 提出日時 | 2017-06-09 22:58:52 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,107 bytes |
| 記録 | |
| コンパイル時間 | 1,965 ms |
| コンパイル使用メモリ | 74,296 KB |
| 実行使用メモリ | 398,080 KB |
| 最終ジャッジ日時 | 2026-04-10 23:32:03 |
| 合計ジャッジ時間 | 5,458 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 18 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:53,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/locale_classes.h:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ios_base.h:43,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ios:46,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:43,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
from main.cpp:1:
In function 'const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = int]',
inlined from 'int main()' at main.cpp:44:25:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:263:15: warning: iteration 1000099 invokes undefined behavior [-Waggressive-loop-optimizations]
263 | if (__a < __b)
| ~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:42:22: note: within this loop
42 | for(int j = 0; j < 1000100; j++){
| ~~^~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
/*
N≤100
1≤vi,wi≤10001≤vi,wi≤1000
0≤V≤100000
*/
// 番号 重さ = 価値
int dp[101][1000100] = {};
int main(void){
int n;
cin >> n;
for(int i = 0; i < n; i++)
for(int j = 0; j < 1000100; j++)
dp[i][j] = -1;
dp[0][0] = 0;
for(int i = 0; i < n; i++){
int v,w;
cin >> v >> w;
for(int j = 1000099; j >= 0; j --){
if(dp[i][j] != -1 && j + w < 1000099){
dp[i+1][j+w] = v + dp[i][j];
dp[i+1][j] = dp[i][j];
//cout << j+w << endl;
}
}
}
int V,Max = 0,Min = 1000100;
cin >> V;
for(int j = 0; j < 1000100; j++){
dp[n][j+1] = max(dp[n][j+1],dp[n][j]);
if(dp[n][j] == V){
Max = max(Max,j);
Min = min(Min,j);
}
}
cout << max(Min,1) << endl;
if(Max > 1000000)
cout << "inf" << endl;
else
cout << Max << endl;
}
Nasatame