| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 507538 | Saeed_247 | Knapsack (NOI18_knapsack) | C++14 | 94 ms | 33152 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int s, n;
cin >> s >> n;
map<int, vector<pair<int, int>>> mp;
for (int i = 1; i <= n; i++) {
int v, w, a;
cin >> v >> w >> a;
if (w <= s && a > 0) {
mp[w].push_back({v, a});
}
}
vector<vector<long long>> dp(mp.size() + 1, vector<long long>(s + 1, INT_MIN));
dp[0][0] = 0;
int i = 1;
for (auto& [w, items] : mp) {
sort(items.begin(), items.end(), greater<pair<int, int>>());
for (int j = 0; j <= s; j++) {
dp[i][j] = dp[i - 1][j];
int amt = 0, curr = 0, used = 0;
long long x = 0;
while ((amt + 1) * w <= j && curr < items.size()) {
amt++;
x += items[curr].first;
if (dp[i - 1][j - amt * w] != INT_MIN) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - amt * w] + x);
}
used++;
if (used == items[curr].second) {
used = 0;
curr++;
}
}
}
i++;
}
cout << *max_element(dp.back().begin(), dp.back().end()) << '\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... | ||||
