| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 784368 | devariaota | Knapsack (NOI18_knapsack) | C++17 | 15 ms | 31836 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<ll,ll>> bycost[2005];
vector<pair<ll,ll>> item;
ll val[100005],cost[100005],freq[100005];
ll memo[2005][2005];
ll idx=0;
ll dp(ll x,ll y){
if(x==item.size()) return 0;
if(y<=0) return 0;
if(memo[x][y]!=-1) return memo[x][y];
//lewat
ll best=dp(x+1,y);
//ambil
if(y>=item[x].second){
best=max(best,dp(x+1,y-item[x].second)+item[x].first);
}
return memo[x][y]=best;
}
int main(){
int t,n;cin>>t>>n;
for(ll i=1;i<=n;i++){
cin>>val[i]>>cost[i]>>freq[i];
bycost[cost[i]].push_back({val[i],freq[i]});
}
int tot=0;
bool masih=true;
for(ll j=1;j<=2000;j++){
if(bycost[j].size()>0){
sort(bycost[j].begin(),bycost[j].end(),greater<pair<ll,ll>>());
for(auto nx:bycost[j]){
for(int i=1;i<=nx.second;i++){
tot+=j;
item.push_back({nx.first,j});
idx++;
if(tot>=2000){
break;
masih=false;
}
}
if(!masih) break;
}
}
if(!masih) break;
}
for(auto nx:item){
cout<<nx.first<<" "<<nx.second<<endl;
}
memset(memo,-1,sizeof memo);
cout<<dp(0,t);
}컴파일 시 표준 에러 (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... | ||||
