結果

問題 No.409 ダイエット
ユーザー 0w10w1
提出日時 2019-10-17 14:02:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 861 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 205,216 KB
実行使用メモリ 64,256 KB
最終ジャッジ日時 2023-09-06 15:27:51
合計ジャッジ時間 7,616 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 3 ms
4,376 KB
testcase_43 AC 3 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 3 ms
4,380 KB
testcase_49 AC 3 ms
4,380 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 3 ms
4,376 KB
testcase_52 AC 3 ms
4,380 KB
testcase_53 AC 3 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 34 ms
11,220 KB
testcase_56 AC 45 ms
4,376 KB
testcase_57 AC 71 ms
20,260 KB
testcase_58 AC 32 ms
10,364 KB
testcase_59 AC 48 ms
16,380 KB
testcase_60 AC 29 ms
9,432 KB
testcase_61 AC 64 ms
17,956 KB
testcase_62 AC 67 ms
19,008 KB
testcase_63 AC 66 ms
21,652 KB
testcase_64 AC 36 ms
13,020 KB
testcase_65 AC 77 ms
31,024 KB
testcase_66 AC 71 ms
20,152 KB
testcase_67 AC 55 ms
15,644 KB
testcase_68 AC 49 ms
18,900 KB
testcase_69 AC 65 ms
21,420 KB
testcase_70 AC 86 ms
16,704 KB
testcase_71 AC 50 ms
11,012 KB
testcase_72 AC 104 ms
19,796 KB
testcase_73 AC 103 ms
26,704 KB
testcase_74 AC 62 ms
12,876 KB
testcase_75 AC 100 ms
22,504 KB
testcase_76 AC 71 ms
14,184 KB
testcase_77 AC 51 ms
14,388 KB
testcase_78 AC 53 ms
11,456 KB
testcase_79 AC 44 ms
9,836 KB
testcase_80 AC 100 ms
18,780 KB
testcase_81 AC 101 ms
22,640 KB
testcase_82 AC 71 ms
14,260 KB
testcase_83 AC 79 ms
15,232 KB
testcase_84 AC 68 ms
18,416 KB
testcase_85 AC 9 ms
4,424 KB
testcase_86 AC 66 ms
17,964 KB
testcase_87 AC 88 ms
16,824 KB
testcase_88 AC 39 ms
9,960 KB
testcase_89 AC 121 ms
57,420 KB
testcase_90 AC 43 ms
16,540 KB
testcase_91 AC 133 ms
64,256 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));

    const int64_t INF = 3e11;
    vector<vector<int64_t>> dp(N + 1, vector<int64_t>(threshold, 3e11));
    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