# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
688413 | koolaider | Knapsack (NOI18_knapsack) | C++17 | 1082 ms | 25096 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define pb push_back
#define ll long long
const int MN = 1e5+2;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*
a b y x b
a 1 1 1 1 1
x 1 1 1 2 2
y 1 1 2 2 2
b 1 2 2 2 3
*/
//#pragma GCC target ("avx,avx2")
//#pragma GCC optimize ("Ofast")
//DSUFlowHyRuthTh!
//const long long ML = 1e18;
//const int MN = 1e9;
const int MM = 1e9+7;
int main(int argc, char **argv){
//ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL);
//setIO("time");
int s, n; cin >> s >> n;
int v, w, k;
vector<int> values; vector<int> weights;
for(int i = 0; i<n; i++){
cin >> v >> w >> k;
for(int j = 0; j<k; j++){
values.pb(v); weights.pb(w);
}
}
int amount = values.size();
ll dp[2+1][s+1]; memset(dp, 0, sizeof(dp));
bool f = true;
for(int y = 1; y<=amount; y++){
for(int x = 1; x<=s; x++){
if(f==true){
if(x-weights[y-1]>=0) dp[1][x]=dp[2][x-weights[y-1]]+values[y-1];
dp[1][x]=max(dp[1][x], dp[2][x]);
}else{
if(x-weights[y-1]>=0) dp[2][x]=dp[1][x-weights[y-1]]+values[y-1];
dp[2][x]=max(dp[2][x], dp[1][x]);
}
}
/*
for(int x = 1; x<=s; x++){
if(f==true){
dp[2][x]=dp[1][x];
}else{
dp[0][x]=dp[2][x];
}
}
*/
f=!f;
}
cout << max(dp[2][s], dp[1][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... |