| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 771145 | 8pete8 | Knapsack (NOI18_knapsack) | C++14 | 76 ms | 36360 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define ll long long
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<pii,int>
#define pll pair<ll,ll>
#define ppll pair<ll,pair<ll,ll>>
#define pbb pair<bool,bool>
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
const int mxn=1e5+1;
#define int long long
int dp[mxn+10][2002];
bool cmp(pii a,pii b){return a.f>b.f;}
int32_t main(){
fastio
int s,n;cin>>s>>n;
map<int,vector<pii>>mp;
for(int i=1;i<=n;i++){
int v,w,k;cin>>v>>w>>k;
mp[w].push_back({v,k});
}
//val, weight, how many
int cnt=1,ans=0;
for(auto i:mp){
sort(i.s.begin(),i.s.end(),cmp);
for(int j=1;j<=s;j++){
dp[cnt][j]=dp[cnt-1][j];
int cur=1,curi=0,cost=0,cnt2=1;
while(curi<i.s.size()&&j-(cnt2*i.f)>=0){
cost+=i.s[curi].f;
dp[cnt][j]=max(dp[cnt-1][j-(cnt2*i.f)]+cost,dp[cnt][j]);
if(cur==i.s[curi].s){
cur=1;
curi++;
}
else cur++;
cnt2++;
}
ans=max(ans,dp[cnt][j]);
}
cnt++;
}
cout<<ans<<'\n';
}컴파일 시 표준 에러 (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... | ||||
