結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー t98slidert98slider
提出日時 2022-07-29 22:50:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,082 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 171,312 KB
実行使用メモリ 56,692 KB
最終ジャッジ日時 2023-09-26 22:19:02
合計ジャッジ時間 15,062 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 57 ms
5,196 KB
testcase_29 AC 66 ms
5,152 KB
testcase_30 AC 68 ms
5,220 KB
testcase_31 AC 62 ms
5,156 KB
testcase_32 AC 55 ms
4,828 KB
testcase_33 AC 91 ms
5,380 KB
testcase_34 AC 79 ms
5,256 KB
testcase_35 AC 35 ms
4,700 KB
testcase_36 AC 52 ms
4,984 KB
testcase_37 AC 55 ms
5,160 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];
    for(int i = n - 1; i >= 0; 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)continue;
            for(int j = min(n - cnt, s); j >= 0; j--){
                for(int l = n - w; l > i; l--){
                    dp[j + cnt][l + w] = max(dp[j + cnt][l + w], dp[j][l] + inc);
                }
            }
            dp[cnt][w] = max(dp[cnt][w], dp[0][0] + inc);
            s += cnt;
        }
    }
    for(int i = 1; i <= n; i++)cout << *max_element(dp[i].begin(), dp[i].end()) << '\n';
}
0