結果

問題 No.37 遊園地のアトラクション
コンテスト
ユーザー siman
提出日時 2021-08-13 19:29:23
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,089 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,128 ms
コンパイル使用メモリ 148,224 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-19 15:47:12
合計ジャッジ時間 6,161 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:23:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   23 |   int C[N];
      |         ^
main.cpp:23:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N;
      |       ^
main.cpp:30:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   30 |   int V[N][100];
      |         ^
main.cpp:30:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N;
      |       ^
main.cpp:43:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   43 |   int dp[T + 1];
      |          ^~~~~
main.cpp:43:10: note: read of non-const variable 'T' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int T;
      |       ^
3 warnings generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int T;
  cin >> T;
  int N;
  cin >> N;

  int c;
  int C[N];
  memset(C, 0, sizeof(C));
  for (int i = 0; i < N; ++i) {
    cin >> C[i];
  }

  int v;
  int V[N][100];
  memset(V, 0, sizeof(V));
  for (int i = 0; i < N; ++i) {
    cin >> v;

    int k = 0;
    while (v > 0) {
      V[i][k] = v;
      v /= 2;
      ++k;
    }
  }

  int dp[T + 1];
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  int ans = 0;

  for (int i = 0; i < N; ++i) {
    for (int t = T - 1; t >= 0; --t) {
      if (dp[t] < 0) continue;
      int k = 0;
      int tv = 0;

      while (V[i][k] > 0) {
        tv += V[i][k];
        int nt = t + C[i] * (k + 1);
        if (T < nt) break;

        int nv = dp[t] + tv;
        dp[nt] = max(dp[nt], nv);
        ans = max(ans, dp[nt]);
        ++k;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0