| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 975172 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 74 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
int s,n;
vector<pair<int,int> > weight[2005];
vector<pair<int,int> > item;
int dp[20005][2005];
int cek(int idx,int brt){
if(brt<0)return -1e15;
if(idx==item.size())return 0;
int &res=dp[idx][brt];
if(res!=-1)return res;
pair<int,int>p=item[idx];
res=max(cek(idx+1,brt),cek(idx+1,brt-p.first)+p.second);
return res;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>s>>n;
for(int r=0;r<n;r++){
int v,w,k;
cin>>v>>w>>k;
weight[w].push_back({v,k});
}
for(int d=1;d<=2000;d++){
sort(weight[d].begin(),weight[d].end());
int maks= 2000/d +1;
while(maks>0 && !weight[d].empty()){
maks--;
pair<int,int> &p=weight[d].back();
item.push_back({d,p.first});
p.second--;
if(p.second==0){
weight[d].pop_back();
}
}
}
memset(dp,-1,sizeof dp);
cout<<cek(0,s);
}
컴파일 시 표준 에러 (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... | ||||
