# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1033440 | 2024-07-24T20:32:15 Z | cryptobunny | Knapsack (NOI18_knapsack) | C++14 | 1 ms | 600 KB |
#include <iostream> #include <vector> #include <cassert> using namespace std; int dp[2001]; int main() { int s, n; cin >> s >> n; vector<int> val, cost; for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; int j; for (j = 30; j >= 1; j--) { if (k >= (1 << j)) { break; } } for (int x = 0; x < j; x++) { val.push_back(v << x); cost.push_back(w << x); k -= 1 << x; } if (k) { val.push_back(v * k); cost.push_back(w * k); } } // vector<int> dp(s + 1); int ans = 0; for (int i = 0; i < val.size(); i++) { assert(i < cost.size()); // cout << val[i] << " " << cost[i] << endl; for (int w = s; w >= cost[i]; w--) { dp[w] = max(dp[w], dp[w - cost[i]] + val[i]); ans = max(ans, dp[w]); } } cout << ans << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Runtime error | 1 ms | 348 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 352 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 352 KB | Output is correct |
5 | Correct | 0 ms | 352 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 436 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 352 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 352 KB | Output is correct |
5 | Correct | 0 ms | 352 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 436 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 344 KB | Output is correct |
16 | Correct | 1 ms | 600 KB | Output is correct |
17 | Correct | 0 ms | 352 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Runtime error | 1 ms | 348 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Runtime error | 1 ms | 348 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |