| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1039231 | Quanmapne | Knapsack (NOI18_knapsack) | C++14 | 42 ms | 3676 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define file "D"
#define ll long long
using namespace std;
const int maxN = 2e3 + 5;
struct points{
int v, k;
};
bool cmp(points a, points b){
if (a.v != b.v)
return a.v > b.v;
return a.k > b.k;
}
int t, n;
int s;
ll dp[maxN];
vector< points > a[maxN];
void solve(){
for (int i = 1; i <= s; ++i){
if (!a[i].size())
continue;
sort(a[i].begin(), a[i].end(), cmp);
int index = 0;
for (int j = 1; j * i <= s; ++j){
if (index == a[i].size())
break;
for (int q = s; q >= i; --q)
dp[q] = max(dp[q], dp[q - i] + a[i][index].v);
a[i][index].k-= 1;
if (a[i][index].k == 0)
++index;
}
}
cout << dp[s];
}
signed main(){
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
cin.tie(NULL)->sync_with_stdio(0);
t = 1;
while (t--){
cin >> s >> n;
for (int i = 1; i <= n; ++i){
int v, w, k;
cin >> v >> w >> k;
a[w].push_back({v, k});
}
solve();
}
}
컴파일 시 표준 에러 (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... | ||||
