| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 888915 | Perl32 | Knapsack (NOI18_knapsack) | C++14 | 47 ms | 3752 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//I wrote this code 4 u <3
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
const int INF = (int) 1e9 + 1e3;
const int maxN = 2024;
ll dp[maxN];
vector<pair<int, int>> srt[maxN];
signed main(int32_t argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int W, n;
cin >> W >> n;
dp[0] = 0;
for (int i = 0; i < n; ++i) {
int s, w, k;
cin >> s >> w >> k;
if (w <= W) {
srt[w].emplace_back(s, k);
}
}
for (auto &x : srt) {
sort(x.rbegin(), x.rend());
}
memset(dp, 0ll, sizeof dp);
for (int i = 1; i <= W; ++i) {
int id = 0, cur = 0;
while (id < (int) srt[i].size() && cur <= W) {
auto [v, k] = srt[i][id];
for (int j = W; j >= i; --j) {
dp[j] = max(dp[j], dp[j - i] + v);
}
if (!(--srt[i][id].second)) {
id++;
}
cur += i;
}
}
ll mx = 0;
for (int i = 0; i <= W; ++i) {
mx = max(mx, dp[i]);
}
cout << mx;
}
/*
*/컴파일 시 표준 에러 (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... | ||||
