結果

問題 No.409 ダイエット
ユーザー 0w10w1
提出日時 2019-10-17 17:14:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 872 bytes
コンパイル時間 2,406 ms
コンパイル使用メモリ 206,276 KB
実行使用メモリ 64,208 KB
最終ジャッジ日時 2023-09-07 01:17:47
合計ジャッジ時間 10,405 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 3 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 3 ms
4,380 KB
testcase_49 AC 3 ms
4,384 KB
testcase_50 AC 3 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 3 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 35 ms
11,216 KB
testcase_56 AC 47 ms
4,380 KB
testcase_57 AC 69 ms
20,088 KB
testcase_58 AC 31 ms
10,152 KB
testcase_59 AC 47 ms
16,304 KB
testcase_60 AC 28 ms
9,356 KB
testcase_61 AC 64 ms
17,932 KB
testcase_62 AC 68 ms
18,992 KB
testcase_63 AC 66 ms
21,952 KB
testcase_64 AC 36 ms
13,068 KB
testcase_65 AC 79 ms
30,896 KB
testcase_66 AC 72 ms
19,872 KB
testcase_67 AC 54 ms
15,632 KB
testcase_68 AC 50 ms
18,588 KB
testcase_69 AC 66 ms
21,432 KB
testcase_70 AC 87 ms
16,776 KB
testcase_71 AC 49 ms
10,776 KB
testcase_72 AC 105 ms
19,844 KB
testcase_73 AC 106 ms
26,708 KB
testcase_74 AC 61 ms
12,780 KB
testcase_75 AC 102 ms
22,560 KB
testcase_76 AC 71 ms
14,084 KB
testcase_77 AC 52 ms
14,452 KB
testcase_78 AC 55 ms
11,496 KB
testcase_79 AC 44 ms
10,152 KB
testcase_80 AC 100 ms
18,768 KB
testcase_81 AC 101 ms
22,504 KB
testcase_82 AC 72 ms
14,368 KB
testcase_83 AC 77 ms
15,456 KB
testcase_84 AC 68 ms
18,412 KB
testcase_85 AC 9 ms
4,432 KB
testcase_86 AC 68 ms
17,772 KB
testcase_87 AC 86 ms
16,760 KB
testcase_88 AC 38 ms
9,972 KB
testcase_89 AC 122 ms
57,364 KB
testcase_90 AC 42 ms
16,576 KB
testcase_91 AC 134 ms
64,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, A, B, W;
  cin >> N >> A >> B >> W;

  vector<int> D(N);
  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }

  if (B == 0) {
    int64_t ans = W - (int64_t) N * A;
    cout << ans << endl;
  } else {
    int maxd = *max_element(D.begin(), D.end());
    int threshold = ceil(2 * sqrt((maxd + A) / B));

    int64_t INF = W + (int64_t) N * maxd;
    vector<vector<int64_t>> dp(N + 1, vector<int64_t>(threshold, INF));
    dp[0][0] = W;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < threshold; ++j) {
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + D[i]);
        if (j + 1 < threshold) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] - A + (int64_t) B * (j + 1));
      }
    }

    int64_t ans = *min_element(dp[N].begin(), dp[N].end());
    cout << ans << endl;
  }

  return 0;
}
0