| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 866591 | 12345678 | Knapsack (NOI18_knapsack) | C++17 | 73 ms | 3160 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, cnt[nx];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, 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;
pq[w].push({v, k});
cnt[w]+=k;
if (cnt[w]-pq[w].top().second>s/w) cnt[w]-=pq[w].top().second, pq[w].pop();
}
vector<pair<int, int>> d;
for (int i=1; i<=s; i++)
{
int tmp=s/i;
stack<pair<int, int>> s;
while (!pq[i].empty()) s.push(pq[i].top()), pq[i].pop();
while (tmp>0&&!s.empty())
{
tmp--;
auto [x, y]=s.top();
s.pop();
d.push_back({i, x});
if (--y!=0) s.push({x, y});
}
}
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... | ||||
