| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 877911 | tigar | Knapsack (NOI18_knapsack) | C++14 | 47 ms | 5096 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s, n;
vector<pair<ll, ll> >w[2020];
ll dp[2020];
bool cmp(pair<ll, ll>a, pair<ll, ll>b)
{
return a.first>b.first;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); //cout.tie(0);
cin>>s>>n;
for(int i=1; i<=n; i++)
{
ll val, weight, countt;
cin>>val>>weight>>countt;
w[weight].push_back({val, countt});
}
for(int i=1; i<=s; i++){sort(w[i].begin(), w[i].end(), cmp); dp[i]=-1;}
for(int i=1; i<=s; i++)
{
for(int j=s; j>=i; j--)
{
int k=1, price=0;
for(int l=0; l<w[i].size(); l++)
{
//cout<<"OVDE\n";
int pff=1;
while(pff<=w[i][l].second and k*i<=j)
{
if(dp[j-k*i]!=-1)dp[j]=max(dp[j-k*i]+price+pff*w[i][l].first, dp[j]);
k++; pff++;
//cout<<l<<" "<<j<<endl;
}
price+=w[i][l].second*w[i][l].first;
if(k*i>j)break;
}
}
}
ll rez=0;
for(int i=1; i<=s; i++)rez=max(rez, dp[i]);
cout<<rez;
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... | ||||
