| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 787001 | Pekiban | Knapsack (NOI18_knapsack) | C++17 | 225 ms | 140860 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <sys/ucontext.h>
#include <vector>
using namespace std;
bool cmp(array<int, 3> a, array<int, 3> b) {
if (a[1] != b[1]) return a[1] < b[1];
return a[0] > b[0];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, s;
cin >> s >> n;
array<int, 3> a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i][0] >> a[i][1] >> a[i][2];
}
sort(a, a+n, cmp);
vector<int> bx[s+1];
int sz = 0;
for (int i = 0; i < n; ++i) {
int d = (s+a[i][1]-1)/a[i][1];
while (bx[a[i][1]].size() < d && a[i][2]) {
bx[a[i][1]].push_back(a[i][0]);
a[i][2]--;
sz++;
}
}
int x[sz], y[sz];
int dp[sz][s+1];
for (int i = 0; i < sz; ++i) {
for (int j = 0; j <= s; ++j) {
dp[i][j] = 0;
}
}
int cnt = 0;
for (int i = 1; i <= s; ++i) {
for (auto u : bx[i]) {
x[cnt] = u;
y[cnt++] = i;
}
}
// for (int i = 0; i < sz; ++i) {
// cout << x[i] << ' ' << y[i] << '\n';
// }
//
// 1)stvorimo jednostavniji niz
// 2) resimo laksi problem
dp[0][0] = 0;
for (int i = 0; i < sz; ++i) {
for (int j = 1; j <= s; ++j) {
dp[i][j] = max((i==0?0:dp[i-1][j]), dp[i][j-1]);
if (j >= y[i]) {
dp[i][j] = max(dp[i][j], (i == 0?0:dp[i-1][j-y[i]])+x[i]);
}
}
}
// for (int i = 0; i < sz; ++i) {
// for (int j = 0; j <= s; ++j) {
// cout << dp[i][j] << ' ';
// }
// cout << '\n';
// }
cout << dp[sz-1][s] << '\n';
}컴파일 시 표준 에러 (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... | ||||
