# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
986968 | Codurr | Knapsack (NOI18_knapsack) | C++14 | 1064 ms | 472 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define int long long //Avoid if time complexity very close to limit
#define ll long long
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f first
#define s second
void setIO(string s="") {
ios_base::sync_with_stdio(0); cin.tie(0);
if(sz(s)) {
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
}
//Imp consts
const int MOD=1e9+7;
const int MAXN=2e5+1;
const int INF=1e18+5;
const double pi=3.14159265358979323846;
const double ep=1e-20;
signed main() {
setIO();
int S,n;
cin>>S>>n;
vector<int> val,pr,cnt;
for(int i=0;i<n;i++) {
int x,y,z;
cin>>x>>y>>z;
val.push_back(x);
pr.push_back(y);
cnt.push_back(z);
}
vector<int> dp(S+1,-1);
dp[0]=0;
for(int i=0;i<n;i++) {
int v=val[i],p=pr[i],c=cnt[i];
for(int j=S;j>=0;j--) {
for(int l=1;l<=c;l++) {
if(j>=l*p&&dp[j-l*p]>=0)
dp[j]=max(dp[j],dp[j-l*p]+v*l);
}
}
}
int ans=0;
for(auto u:dp)
ans=max(ans,u);
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... |