結果
問題 | No.527 ナップサック容量問題 |
ユーザー | le_panda_noir |
提出日時 | 2020-06-14 14:05:51 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 828 bytes |
コンパイル時間 | 596 ms |
コンパイル使用メモリ | 75,200 KB |
実行使用メモリ | 42,844 KB |
最終ジャッジ日時 | 2023-09-09 14:31:43 |
合計ジャッジ時間 | 2,804 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,128 KB |
testcase_01 | AC | 3 ms
5,212 KB |
testcase_02 | AC | 2 ms
4,504 KB |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 11 ms
19,600 KB |
testcase_06 | AC | 24 ms
38,140 KB |
testcase_07 | WA | - |
testcase_08 | AC | 10 ms
17,848 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | WA | - |
testcase_11 | AC | 16 ms
27,976 KB |
testcase_12 | AC | 12 ms
21,656 KB |
testcase_13 | AC | 23 ms
38,076 KB |
testcase_14 | WA | - |
testcase_15 | AC | 15 ms
24,136 KB |
testcase_16 | AC | 4 ms
5,148 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 10 ms
17,628 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 5 ms
7,312 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 14 ms
25,920 KB |
testcase_36 | WA | - |
testcase_37 | AC | 11 ms
19,704 KB |
testcase_38 | AC | 13 ms
23,808 KB |
testcase_39 | AC | 14 ms
23,812 KB |
ソースコード
#include <iostream> #include <vector> using namespace std; using vi = vector<int>; #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) constexpr int MAX_V = 1e5+2; int dp[101][MAX_V]; int main() { int N; cin >> N; vi v(N), w(N); rep(i, N) cin >> v[i] >> w[i]; int V; cin >> V; // dp[i][v] = i番目までで価値の総和がちょうどvのときの容量の最小値 rep(i, N+1) rep(j, MAX_V) { dp[i][j] = -1; } dp[0][0] = 0; rep(i, N) rep(j, MAX_V) { dp[i+1][j] = dp[i][j]; if (dp[i][j-v[i]] == -1) continue; if (dp[i+1][j] == -1) dp[i+1][j] = dp[i][j-v[i]] + w[i]; else dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i]); } cout << max(1, dp[N][V]) << endl; if (dp[N][V+1] == -1) cout << "inf\n"; else cout << dp[N][V+1]-1 << endl; return 0; }