# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
886373 | Zero_OP | Knapsack (NOI18_knapsack) | C++14 | 1029 ms | 19140 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define range(v) begin(v), end(v)
#define compact(v) v.erase(unique(range(v)), end(v))
template<class T> bool minimize(T& a, T b){
if(a > b) return a = b, true;
return false;
}
template<class T> bool maximize(T& a, T b){
if(a < b) return a = b, true;
return false;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int S, n;
void Zero_OP(){
cin >> S >> n;
vector<pair<ll, int>> items;
while(n--){
int v, w, k;
cin >> v >> w >> k;
int pw2 = 1;
while(k >= pw2){
k -= pw2;
if(1LL * w * pw2 <= 1LL * S){
items.push_back({1LL * v * pw2, w * pw2});
}
pw2 <<= 1;
}
if(k > 0 and 1LL * w * k <= S){
items.push_back({1LL * v * k, w * k});
}
}
vector<ll> dp(S + 1, -1e18);
dp[0] = 0;
for(auto [earn, weight] : items){
for(int i = S; i >= weight; --i){
maximize(dp[i], dp[i - weight] + earn);
}
}
cout << *max_element(range(dp));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#define task "antuvu"
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
Zero_OP();
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... |