結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー 👑 Nachia
提出日時 2022-07-29 23:22:07
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,290 bytes
コンパイル時間 3,765 ms
コンパイル使用メモリ 127,740 KB
最終ジャッジ日時 2025-01-30 15:45:08
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

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>> WCV;
    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){
            WCV.push_back({w*d,d,v*d});
            c -= d;
            if(d&c){
                WCV.push_back({w*d,d,v*d});
                c -= d;
            }
        }
    }
    sort(WCV.rbegin(), WCV.rend());

    rep(i,N+1) rep(j,N+1) dp[i][j] = -INF;
    rep(i,N+1) dp[0][i] = 0;
    
    for(auto [w,C,V] : WCV){
        for(i64 k=N-C+1; k>=C; k--){
            for(i64 i=w; i<=N; i++){
                dp[k][i] = max(dp[k][i], dp[k-C][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