| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 760327 | sofija6 | Knapsack (NOI18_knapsack) | C++14 | 36 ms | 2880 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define MAXN 100010
#define MAXS 2010
using namespace std;
vector<pair<ll,ll> > items[MAXS];
vector<pair<ll,ll> > cur;
ll dp[MAXS][2];
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll s,n,v,w,k,ans=0;
cin >> s >> n;
for (ll i=1;i<=n;i++)
{
cin >> v >> w >> k;
items[w].push_back({v,k});
}
for (ll i=1;i<=s;i++)
{
if (items[i].empty())
continue;
sort(items[i].begin(),items[i].end(),greater<pair<ll,ll> >());
cur.clear();
ll sum=0,pos=0;
for (ll j=0;(j+1)*i<=s;j++)
{
if (!items[i][pos].second)
pos++;
if (pos==items[i].size())
break;
items[i][pos].second--;
sum+=items[i][pos].first;
cur.push_back({(j+1)*i,sum});
}
for (auto j : cur)
{
w=j.first;
v=j.second;
for (ll l=0;l+w<=s;l++)
dp[l+w][1]=max(dp[l+w][1],dp[l][0]+v);
}
for (ll j=0;j<=s;j++)
dp[j][0]=dp[j][1];
}
for (ll i=1;i<=s;i++)
ans=max(ans,dp[i][0]);
cout << ans;
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... | ||||
