結果

問題 No.409 ダイエット
ユーザー kimiyukikimiyuki
提出日時 2016-10-20 03:30:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,142 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 80,092 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 05:53:32
合計ジャッジ時間 6,822 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 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 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 3 ms
5,376 KB
testcase_41 AC 3 ms
5,376 KB
testcase_42 AC 3 ms
5,376 KB
testcase_43 AC 3 ms
5,376 KB
testcase_44 AC 3 ms
5,376 KB
testcase_45 AC 3 ms
5,376 KB
testcase_46 AC 3 ms
5,376 KB
testcase_47 AC 3 ms
5,376 KB
testcase_48 AC 3 ms
5,376 KB
testcase_49 AC 3 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 3 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 3 ms
5,376 KB
testcase_54 AC 3 ms
5,376 KB
testcase_55 AC 30 ms
5,376 KB
testcase_56 AC 54 ms
5,376 KB
testcase_57 AC 60 ms
6,716 KB
testcase_58 AC 26 ms
5,376 KB
testcase_59 AC 38 ms
5,376 KB
testcase_60 AC 23 ms
5,376 KB
testcase_61 AC 53 ms
6,188 KB
testcase_62 AC 55 ms
6,508 KB
testcase_63 AC 51 ms
6,180 KB
testcase_64 AC 28 ms
5,376 KB
testcase_65 AC 55 ms
6,480 KB
testcase_66 AC 60 ms
6,556 KB
testcase_67 AC 46 ms
5,912 KB
testcase_68 AC 37 ms
5,376 KB
testcase_69 AC 51 ms
6,280 KB
testcase_70 AC 79 ms
5,980 KB
testcase_71 AC 45 ms
5,376 KB
testcase_72 AC 96 ms
6,564 KB
testcase_73 AC 88 ms
6,344 KB
testcase_74 AC 55 ms
5,376 KB
testcase_75 AC 88 ms
6,480 KB
testcase_76 AC 64 ms
5,548 KB
testcase_77 AC 44 ms
5,376 KB
testcase_78 AC 49 ms
5,376 KB
testcase_79 AC 39 ms
5,376 KB
testcase_80 AC 90 ms
6,508 KB
testcase_81 AC 90 ms
6,208 KB
testcase_82 AC 67 ms
5,568 KB
testcase_83 AC 72 ms
5,620 KB
testcase_84 AC 59 ms
5,376 KB
testcase_85 AC 8 ms
5,376 KB
testcase_86 AC 56 ms
5,376 KB
testcase_87 AC 80 ms
6,112 KB
testcase_88 AC 33 ms
5,376 KB
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
const ll inf = ll(1e18)+9;
int main() {
    // input
    int n, a, b, w; cin >> n >> a >> b >> w;
    vector<int> d(n); repeat (i,n) cin >> d[i];
    if (b == 0) {
        // output
        cout << w - a*(ll)n << endl;
    } else {
        // dp
        n += 1;
        d.push_back(0);
        int limit = sqrt((*whole(max_element, d) + a) / b) + 3;
        vector<ll> dp(n+1);
        dp[0] = w;
        repeat (i,n) {
            ll acc = inf;
            repeat_reverse (j,i+1) {
                setmin(acc, dp[j] - a *(ll) ll(i-j) + b *(ll) (i-j)*(i-j+1)/2);
                if (i-j > limit) break;
            }
            dp[i+1] = acc + d[i];
        }
        // output
        cout << dp[n] << endl;
    }
    return 0;
}
0