結果

問題 No.409 ダイエット
ユーザー 0w10w1
提出日時 2019-10-17 14:01:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 861 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 204,960 KB
実行使用メモリ 47,912 KB
最終ジャッジ日時 2023-09-06 15:26:42
合計ジャッジ時間 10,811 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 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 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 WA -
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 WA -
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 3 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 3 ms
4,380 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 2 ms
4,384 KB
testcase_50 AC 3 ms
4,380 KB
testcase_51 AC 3 ms
4,380 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 3 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 WA -
testcase_56 AC 47 ms
4,380 KB
testcase_57 AC 71 ms
20,056 KB
testcase_58 AC 32 ms
10,176 KB
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 AC 67 ms
19,008 KB
testcase_63 AC 62 ms
17,892 KB
testcase_64 AC 35 ms
11,008 KB
testcase_65 WA -
testcase_66 AC 72 ms
20,004 KB
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 AC 49 ms
10,704 KB
testcase_72 WA -
testcase_73 WA -
testcase_74 AC 62 ms
12,940 KB
testcase_75 WA -
testcase_76 AC 70 ms
14,180 KB
testcase_77 WA -
testcase_78 AC 53 ms
11,620 KB
testcase_79 AC 42 ms
9,704 KB
testcase_80 AC 99 ms
18,880 KB
testcase_81 AC 101 ms
22,504 KB
testcase_82 WA -
testcase_83 AC 78 ms
15,132 KB
testcase_84 WA -
testcase_85 AC 9 ms
4,376 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 37 ms
9,944 KB
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
権限があれば一括ダウンロードができます

ソースコード

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(sqrt(2 * (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