| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 735909 | asdfgrace | Knapsack (NOI18_knapsack) | C++17 | 81 ms | 4940 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) //x
#define A(x) DEBUG(assert(x))
#define PRINT(x) DEBUG(cerr << x)
#define PV(x) DEBUG(cerr << #x << " = " << x << '\n')
#define PV2(x) DEBUG(cerr << #x << " = " << x.first << ',' << x.second << '\n')
#define PAR(x) DEBUG(PRINT(#x << " = { "); for (auto y : x) PRINT(y << ' '); PRINT("}\n");)
#define PAR2(x) DEBUG(PRINT(#x << " = { "); for (auto [y, z] : x) PRINT(y << ',' << z << " "); PRINT("}\n");)
typedef int64_t i64;
const int INF = 1000000007; //998244353;
struct S {
int s, n;
vector<vector<pair<i64, i64>>> a;
void run() {
cin >> s >> n;
a.resize(s + 1);
for (int i = 0; i < n; ++i) {
i64 v, w, k;
cin >> v >> w >> k;
a[w].push_back({v, k});
}
vector<i64> cur(s + 1, -1), prev(s + 1, -1);
cur[0] = 0; prev[0] = 0;
for (int i = 0; i <= s; ++i) {
if (a[i].empty()) continue;
sort(a[i].begin(), a[i].end());
reverse(a[i].begin(), a[i].end());
for (int j = 0; j <= s; ++j) {
PV(j);
cur[j] = prev[j];
i64 used = 0LL, elem = 0LL, last = 0LL, val = 0LL;
while (elem < a[i].size() && (used + 1) * i <= j) {
++used;
val += a[i][elem].first;
if (prev[j - i * used] != -1 && i * used <= j) {
cur[j] = max(cur[j], prev[j - i * used] + val);
}
++last;
if (last == a[i][elem].second) {
++elem;
last = 0;
}
}
}
PAR(cur);
prev = cur;
}
PAR(cur);
i64 ans = 0;
for (int i = 0; i <= s; ++i) {
ans = max(ans, cur[i]);
}
cout << ans << '\n';
}
};
int main() {
ios::sync_with_stdio(0); cin.tie(0);
auto sol = make_unique<S>();
sol->run();
}
컴파일 시 표준 에러 (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... | ||||
