| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 963257 | biank | Knapsack (NOI18_knapsack) | C++14 | 45 ms | 5132 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define sz(x) int(x.size())
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int s, n;
cin >> s >> n;
vector<ii> items[s + 1];
for (int i = 0; i < n; i++) {
ll v, w, k;
cin >> v >> w >> k;
items[w].emplace_back(v, k);
}
vector<ll> dp(s + 1, 0);
for (int w = 1; w <= s; w++) {
sort(all(items[w]), greater<ii>());
int i = 0;
for (ll cant = 1; cant * w <= s && i < sz(items[w]); cant++) {
auto &[v, k] = items[w][i];
for (int j = s; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
if (--k == 0) i++;
}
}
cout << dp[s] << '\n';
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... | ||||
