結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー 👑 NachiaNachia
提出日時 2022-07-29 23:26:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 10,000 ms
コード長 1,325 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 92,080 KB
実行使用メモリ 52,588 KB
最終ジャッジ日時 2023-09-26 23:13:40
合計ジャッジ時間 5,925 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 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,376 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 3 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 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,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 11 ms
12,568 KB
testcase_29 AC 12 ms
12,436 KB
testcase_30 AC 12 ms
12,428 KB
testcase_31 AC 11 ms
12,424 KB
testcase_32 AC 10 ms
12,548 KB
testcase_33 AC 13 ms
12,496 KB
testcase_34 AC 13 ms
12,596 KB
testcase_35 AC 9 ms
10,348 KB
testcase_36 AC 11 ms
12,456 KB
testcase_37 AC 11 ms
12,456 KB
testcase_38 AC 422 ms
52,452 KB
testcase_39 AC 369 ms
52,456 KB
testcase_40 AC 384 ms
52,468 KB
testcase_41 AC 418 ms
52,372 KB
testcase_42 AC 416 ms
52,588 KB
testcase_43 AC 418 ms
52,376 KB
testcase_44 AC 420 ms
52,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <atcoder/modint>

using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const i64 INF = 1001001001001001001;
using modint = atcoder::static_modint<998244353>;


i64 dp[2501][2501];


int main(){
    int N; cin >> N;
    vector<tuple<i64,i64,i64,i64>> wWVD;
    rep(i,N){
        i64 w, c, v; w = i+1; cin >> c >> v;
        c = min(c,N/w);
        for(i64 d=1; d<=c; d*=2){
            wWVD.push_back({w,w*d,v*d,d});
            c -= d;
            if(d&c){
                wWVD.push_back({w,w*d,v*d,d});
                c -= d;
            }
        }
    }
    sort(wWVD.rbegin(), wWVD.rend());

    rep(i,N+1) rep(j,N+1) dp[i][j] = -INF;
    rep(i,N+1) dp[0][i] = 0;
    
    for(auto [w,W,V,D] : wWVD){
        i64 K = N / w;
        for(i64 k=K; k>=D; k--){
            for(i64 i=W; i<=N; i++){
                dp[k][i] = max(dp[k][i], dp[k-D][i-W] + V);
            }
        }
    }

    for(int k=1; k<=N; k++) cout << dp[k][N] << '\n';
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0