| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1079033 | Albara_Abdulhafith | Knapsack (NOI18_knapsack) | C++17 | 106 ms | 129304 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
#define all(x) x.begin(),x.end()
#define take(x) for(int &el : x){ cin >> el;}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const int MAX_N = 105;
const int MAX_K = 15;
const int MAX_S = 2005;
int n, S, k, tot_size;
ll v, w;
ll memo[MAX_N * MAX_K][MAX_S];
vector<ll> V, W;
ll dp(int id, ll remW) {
    if(remW == 0 || id == tot_size || W[id] > remW){return 0;}
    if(memo[id][remW] != -1){return memo[id][remW];}
    return memo[id][remW] = max(V[id] + dp(id + 1, remW - W[id]), dp(id + 1, remW));
}
void solve(){
    scanf("%d %d", &S, &n);
    memset(memo, -1, sizeof memo);
    V.clear();
    W.clear();
    for(int i = 0; i < n; i++) {
        scanf("%lld %lld %d", &v, &w, &k);
        for(int j = 0; j < k; j++) {
            V.push_back(v);
            W.push_back(w);
        }
    }
    tot_size = (int)V.size();
    ll ans = dp(0, S);
    printf("%lld\n", ans);
}
int main(){
    fastIO;
    int tc = 1;
    // scanf("%d", &tc);
    while (tc--) {
        solve();
    }
    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... | ||||
