| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 866586 | 12345678 | Knapsack (NOI18_knapsack) | C++17 | 1089 ms | 1372 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=2e3+5;
int s, n, v, w, k, dp[2][nx], mx;
priority_queue<int, vector<int>, greater<int>> pq[nx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>s>>n;
for (int i=0; i<n; i++)
{
cin>>v>>w>>k;
for (int j=0; j<min(k, s/w); j++)
{
pq[w].push(v);
if (pq[w].size()>s/w) pq[w].pop();
}
}
vector<pair<int, int>> d;
for (int i=1; i<=s; i++)
{
while (!pq[i].empty())
{
auto x=pq[i].top();
pq[i].pop();
d.push_back({i, x});
}
}
for (int i=0; i<d.size(); i++)
{
int c=i%2, p=1-c;
v=d[i].second; w=d[i].first;
//cout<<v<<' '<<w<<'\n';
for (int j=1; j<=s; j++)
{
dp[c][j]=dp[p][j];
if (j>=w) dp[c][j]=max(dp[c][j], dp[p][j-w]+v);
mx=max(mx, dp[c][j]);
}
}
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... | ||||
