結果

問題 No.37 遊園地のアトラクション
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-19 23:59:01
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 952 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 145,124 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-29 02:35:22
合計ジャッジ時間 2,438 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 3 ms
6,948 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 11 ms
12,032 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 8 ms
9,856 KB
testcase_11 AC 8 ms
9,600 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 5 ms
7,040 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 10 ms
11,392 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 5 ms
6,944 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 14 ms
15,104 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>

using namespace std;

int main(){

    long long T, N, x, mx=0;
    cin >> T >> N;
    vector<long long> c(N), v(N);
    for (int i=0; i<N; i++) cin >> c[i];
    for (int j=0; j<N; j++) cin >> v[j];
    for (int i=0; i<N; i++){
        x = v[i];
        while(x != 0){
            c.push_back(c[i]);
            v.push_back(x/2);
            x /= 2;
        }
    }
    N = c.size();
    vector<vector<long long>> dp(N+1, vector<long long>(T+1));

    for (int i=1; i<=N; i++){
        for (int j=0; j<=T; j++){
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if (j-c[i-1]>=0) dp[i][j] = max(dp[i][j], dp[i-1][j-c[i-1]]+v[i-1]);
        }
    }

    for (int i=0; i<=T; i++) mx = max(mx, dp[N][i]);
    cout << mx << endl;

    return 0;
}
0