結果

問題 No.37 遊園地のアトラクション
ユーザー なおなお
提出日時 2014-10-10 00:08:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 918 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 62,040 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-18 19:26:29
合計ジャッジ時間 1,470 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,136 KB
testcase_01 AC 4 ms
11,212 KB
testcase_02 AC 6 ms
11,264 KB
testcase_03 AC 4 ms
11,392 KB
testcase_04 AC 5 ms
11,136 KB
testcase_05 AC 5 ms
11,264 KB
testcase_06 AC 5 ms
11,264 KB
testcase_07 AC 7 ms
11,264 KB
testcase_08 AC 4 ms
11,180 KB
testcase_09 AC 4 ms
11,232 KB
testcase_10 AC 5 ms
11,136 KB
testcase_11 AC 5 ms
11,108 KB
testcase_12 AC 5 ms
11,204 KB
testcase_13 AC 5 ms
11,264 KB
testcase_14 AC 6 ms
11,264 KB
testcase_15 AC 9 ms
11,264 KB
testcase_16 AC 5 ms
11,164 KB
testcase_17 AC 4 ms
11,044 KB
testcase_18 AC 4 ms
11,264 KB
testcase_19 AC 4 ms
11,392 KB
testcase_20 AC 5 ms
11,136 KB
testcase_21 AC 5 ms
11,264 KB
testcase_22 AC 5 ms
11,208 KB
testcase_23 AC 4 ms
11,136 KB
testcase_24 AC 4 ms
10,992 KB
testcase_25 AC 4 ms
11,264 KB
testcase_26 AC 4 ms
11,264 KB
testcase_27 AC 4 ms
11,140 KB
testcase_28 AC 5 ms
11,216 KB
testcase_29 AC 5 ms
11,264 KB
testcase_30 AC 5 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))

int T, N, C[16], V;
int dp[200][10010];
int main(){
    cin >> T >> N;
    REP(i,N) cin >> C[i];
    vector<pair<int,int> >v;
    REP(i,N){
        cin >> V;
        while(V){
            v.push_back(make_pair(V,C[i]));
            V /= 2;
        }
    }

    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;

    int s = v.size();
    REP(i,s){
        int k = v[i].first, c = v[i].second;
        REP(j,T+1){
            if(dp[i][j] < 0) continue;
            if(j + c <= T){
                dp[i+1][j+c] = max(dp[i+1][j+c], dp[i][j] + k);
            }
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    int maxv = 0;
    REP(j,T+1) maxv = max(maxv, dp[s][j]);
    cout << maxv << endl;
    return 0;
}
0