結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー 👑 NachiaNachia
提出日時 2022-07-29 22:26:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5,115 ms / 10,000 ms
コード長 1,168 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 85,236 KB
実行使用メモリ 52,332 KB
最終ジャッジ日時 2023-09-26 21:47:23
合計ジャッジ時間 38,274 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 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 3 ms
4,504 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 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 22 ms
12,348 KB
testcase_29 AC 27 ms
12,396 KB
testcase_30 AC 26 ms
12,328 KB
testcase_31 AC 26 ms
12,328 KB
testcase_32 AC 20 ms
12,216 KB
testcase_33 AC 32 ms
12,356 KB
testcase_34 AC 28 ms
12,492 KB
testcase_35 AC 17 ms
10,228 KB
testcase_36 AC 24 ms
12,348 KB
testcase_37 AC 25 ms
12,252 KB
testcase_38 AC 5,104 ms
52,252 KB
testcase_39 AC 4,123 ms
52,236 KB
testcase_40 AC 4,387 ms
52,244 KB
testcase_41 AC 5,088 ms
52,276 KB
testcase_42 AC 5,108 ms
52,164 KB
testcase_43 AC 5,042 ms
52,164 KB
testcase_44 AC 5,115 ms
52,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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;


i64 dp[2501][2501];


int main(){
    int N; cin >> N;
    vector<pair<i64,i64>> CV(N+1);
    rep(i,N) cin >> CV[i+1].first >> CV[i+1].second;
    rep(i,N+1) rep(j,N+1) dp[i][j] = -INF;
    rep(i,N+1) dp[0][i] = 0;
    
    for(i64 w=N; w>=1; w--){
        i64 V = CV[w].second;
        i64 K = N / w;
        i64 C = min(K, CV[w].first);
        for(i64 k=K; k>=1; k--){
            for(i64 c=min(k,C); c>0; c--){
                for(i64 i=w*c; i<=N; i++){
                    dp[k][i] = max(dp[k][i], dp[k-c][i-w*c] + V*c);
                }
            }
        }
    }

    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