結果

問題 No.37 遊園地のアトラクション
ユーザー codershifthcodershifth
提出日時 2015-07-23 23:56:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,522 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 169,612 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-04-18 19:39:03
合計ジャッジ時間 2,973 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 4 ms
5,632 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 9 ms
10,880 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 8 ms
9,088 KB
testcase_11 AC 7 ms
9,088 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 5 ms
6,656 KB
testcase_17 AC 4 ms
6,016 KB
testcase_18 AC 8 ms
10,624 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 4 ms
5,632 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 12 ms
13,824 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class AmusementParkAttraction {
public:
    void solve(void) {
            int T,N;
            cin>>T>>N;
            vector<int> C(N);
            REP(i,N)
                cin>>C[i];
            vector<int> V(N);
            REP(i,N)
                cin>>V[i];
            vector<pair<int,int>> V2;
            REP(i,N)
            {
                int v = V[i];
                while (v > 0)
                {
                    V2.emplace_back(C[i],v);
                    v /= 2;
                }
            }
            // V2.size() <= 15*log2(500) <= 135
            // 後は通常どおり DP
            N = V2.size();
            vector<vector<ll>> dp(N+1, vector<ll>(T+1,0));
            REP(i,N)
            REP(t,T+1)
            {
                int c,v;
                tie(c,v) = V2[i];
                if (c <= t)
                    dp[i+1][t-c] = max(dp[i+1][t-c], dp[i][t]+v);
                dp[i+1][t] = max(dp[i+1][t], dp[i][t]);
            }
            ll res = 0;
            REP(t,T+1)
                res = max(res,dp[N][t]);
            cout<<res<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new AmusementParkAttraction();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0