| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1319422 | f0rsworn | Knapsack (NOI18_knapsack) | C++20 | 1096 ms | 16060 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[2001];
int main() {
int S, n;
scanf("%d%d", &S, &n);
memset(dp, 0, sizeof(dp));
vector<ll> val, weights;
for (int i = 0; i < n; ++i) {
int v, w, k;
scanf("%d%d%d", &v, &w, &k);
int cnt = 1;
while (k > 0) {
int take = min(cnt, k);
val.push_back(1LL * v * take);
weights.push_back(1LL * w * take);
k -= take;
cnt <<= 1;
}
}
int N = val.size();
for (int i = 0; i < N; ++i) {
for (int s = S; s >= weights[i]; --s) {
dp[s] = max(dp[s], val[i] + dp[s - weights[i]]);
}
}
printf("%lld\n", dp[S]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
