| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1331300 | ledinhmanh0401 | Knapsack (NOI18_knapsack) | C++20 | 1095 ms | 472 KiB |
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
using namespace std;
const ll MOD = 1e9+7;
void setup(){
if(fopen("input.INP", "r")){
freopen("input.INP", "r", stdin);
freopen("output.OUT", "w", stdout);
}
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
ll dp[2005],old[2005];
int main(){
setup();
int s,n;
cin>>s>>n;
for(int i=0;i<n;i++){
ll v,w,k;
cin>>v>>w>>k;
if(w>s) continue;
if(k>s/w) k=s/w;
for(int j=0;j<=s;j++)
old[j]=dp[j];
for(int r=0;r<w;r++){
deque<int> q;
for(int j=r,t=0;j<=s;j+=w,t++){
while(!q.empty() && q.front()<t-k)
q.pop_front();
while(!q.empty() && old[r+q.back()*w]-q.back()*v<= old[j]-t*v)
q.pop_back();
q.push_back(t);
dp[j]=old[r+q.front()*w]+(t-q.front())*v;
}
}
}
cout<<dp[s];
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... | ||||
