結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー t98slidert98slider
提出日時 2022-07-29 22:28:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 991 bytes
コンパイル時間 1,529 ms
コンパイル使用メモリ 171,404 KB
実行使用メモリ 175,784 KB
最終ジャッジ日時 2023-09-26 21:49:21
合計ジャッジ時間 15,150 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 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,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 85 ms
5,108 KB
testcase_29 AC 98 ms
5,156 KB
testcase_30 AC 98 ms
5,108 KB
testcase_31 AC 94 ms
5,020 KB
testcase_32 AC 82 ms
4,764 KB
testcase_33 AC 132 ms
5,308 KB
testcase_34 AC 116 ms
5,076 KB
testcase_35 AC 54 ms
4,888 KB
testcase_36 AC 74 ms
4,972 KB
testcase_37 AC 79 ms
4,960 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;
    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 cnt, w = 0, inc;
    for(int i = 0; i < n; i++){
        cin >> c[i] >> v[i];
        for(int j = 0; j < 23 && c[i] > 0; j++){
            if(c[i] >= (1 << j)){
                c[i] -= (1 << j);
                cnt = 1 << j;
                w = (i + 1) * cnt;
                inc = v[i] * cnt;
            }else{
                cnt = c[i];
                w = (i + 1) * cnt;
                inc = v[i] * cnt;
                c[i] = 0;
            }
            for(int i = n - cnt; i >= 0; i--){
                for(int j = n - w; j >= 0; j--){
                    dp[i + cnt][j + w] = max(dp[i + cnt][j + w], dp[i][j] + inc);
                }
            }
        }
    }
    for(int i = 1; i <= n; i++)cout << *max_element(dp[i].begin(), dp[i].end()) << '\n';
}
0