| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 754981 | hieupham1103 | Knapsack (NOI18_knapsack) | C++17 | 87 ms | 4904 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ii pair <int,int>
#define fi first
#define se second
#define int long long
#define double long double
#define endl '\n'
#define all(x) x.begin(), x.end()
using namespace std;
struct good{
int p,w,k;
};
good a[(int)1e5 + 10];
bool cmp(good x, good y){
if (x.w == y.w){
return x.p > y.p;
}
return x.w < y.w;
}
vector <int> sto[2010];
int dp[2010];
signed main(){
//freopen("input.INP", "r", stdin);
//freopen("output.OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, W;
cin >> W >> n;
for (int i = 1; i <= n; i++){
cin >> a[i].p >> a[i].w >> a[i].k;
}
sort(a + 1, a + 1 + n, cmp);
for (int i = 1; i <= n; i++){
while(a[i].k and sto[a[i].w].size() < W / a[i].w){
sto[a[i].w].push_back(a[i].p);
a[i].k--;
}
}
// for (int w = 1; w <= W; w++){
// if (sto[w].size() == 0){
// continue;
// }
// cout << w << ": ";
// for (auto p: sto[w]){
// cout << p << " ";
// }
// cout << endl;
// }
// cout << endl;
int res = 0;
for (int w = 1; w <= W; w++){
for (auto p: sto[w]){
for (int s = W - w; s >= 0; s--){
dp[s + w] = max(dp[s + w], dp[s] + p);
res = max(res, dp[s + w]);
// cout << w << ' ' << p << ": " << s + w << " " << dp[s + w] << endl;
}
}
}
// for (int i = 1; i <= W; i++){
// cout << i << ": " << dp[i] << endl;
// }
cout << res << endl;
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... | ||||
