結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー t98slidert98slider
提出日時 2022-07-29 22:40:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,038 bytes
コンパイル時間 1,657 ms
コンパイル使用メモリ 171,012 KB
実行使用メモリ 56,644 KB
最終ジャッジ日時 2023-09-26 22:05:51
合計ジャッジ時間 15,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,504 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 82 ms
5,280 KB
testcase_29 AC 95 ms
5,208 KB
testcase_30 AC 99 ms
5,132 KB
testcase_31 AC 94 ms
5,124 KB
testcase_32 AC 80 ms
4,840 KB
testcase_33 AC 134 ms
5,312 KB
testcase_34 AC 114 ms
5,112 KB
testcase_35 AC 52 ms
4,728 KB
testcase_36 AC 76 ms
4,940 KB
testcase_37 AC 78 ms
4,996 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n, s = 0, s2 = 0;
    cin >> n;
    vector<ll> c(n), v(n);
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, -(1ll << 62)));
    dp[0][0] = 0;
    ll inc;
    for(int i = 0; i < n; i++){
        cin >> c[i] >> v[i];
        int cnt, w;
        for(int j = 0; j < 13 && c[i] > 0; j++){
            if(c[i] >= (1 << j)){
                c[i] -= (1 << j);
                cnt = 1 << j;
            }else{
                cnt = c[i];
                c[i] = 0;
            }
            w = (i + 1) * cnt;
            inc = v[i] * cnt;
            if(w > n){s2 = n; continue;}
            for(int i = min(n - cnt, s); i >= 0; i--){
                for(int j = min(n - w, s2); j >= 0; j--){
                    dp[i + cnt][j + w] = max(dp[i + cnt][j + w], dp[i][j] + inc);
                }
            }
            s += cnt, s2 = min(s2 + w, n);
        }
    }
    for(int i = 1; i <= n; i++)cout << *max_element(dp[i].begin(), dp[i].end()) << '\n';
}
0