結果

問題 No.409 ダイエット
ユーザー kimiyukikimiyuki
提出日時 2016-10-20 02:06:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 565 ms / 2,000 ms
コード長 1,137 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 78,232 KB
実行使用メモリ 6,448 KB
最終ジャッジ日時 2023-09-08 17:12:26
合計ジャッジ時間 12,922 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 6 ms
4,380 KB
testcase_37 AC 6 ms
4,376 KB
testcase_38 AC 6 ms
4,376 KB
testcase_39 AC 6 ms
4,376 KB
testcase_40 AC 6 ms
4,380 KB
testcase_41 AC 7 ms
4,376 KB
testcase_42 AC 6 ms
4,376 KB
testcase_43 AC 6 ms
4,376 KB
testcase_44 AC 6 ms
4,376 KB
testcase_45 AC 6 ms
4,380 KB
testcase_46 AC 6 ms
4,376 KB
testcase_47 AC 6 ms
4,380 KB
testcase_48 AC 6 ms
4,376 KB
testcase_49 AC 7 ms
4,380 KB
testcase_50 AC 6 ms
4,376 KB
testcase_51 AC 6 ms
4,380 KB
testcase_52 AC 6 ms
4,376 KB
testcase_53 AC 6 ms
4,380 KB
testcase_54 AC 6 ms
4,380 KB
testcase_55 AC 28 ms
4,880 KB
testcase_56 AC 47 ms
4,376 KB
testcase_57 AC 57 ms
6,420 KB
testcase_58 AC 25 ms
4,476 KB
testcase_59 AC 36 ms
5,284 KB
testcase_60 AC 23 ms
4,484 KB
testcase_61 AC 51 ms
6,120 KB
testcase_62 AC 53 ms
6,448 KB
testcase_63 AC 49 ms
5,944 KB
testcase_64 AC 27 ms
4,420 KB
testcase_65 AC 51 ms
5,976 KB
testcase_66 AC 56 ms
6,272 KB
testcase_67 AC 43 ms
5,672 KB
testcase_68 AC 34 ms
5,172 KB
testcase_69 AC 48 ms
6,132 KB
testcase_70 AC 462 ms
5,712 KB
testcase_71 AC 257 ms
4,376 KB
testcase_72 AC 565 ms
6,276 KB
testcase_73 AC 520 ms
6,136 KB
testcase_74 AC 327 ms
4,868 KB
testcase_75 AC 530 ms
6,180 KB
testcase_76 AC 372 ms
5,176 KB
testcase_77 AC 250 ms
4,684 KB
testcase_78 AC 287 ms
4,812 KB
testcase_79 AC 228 ms
4,448 KB
testcase_80 AC 534 ms
6,416 KB
testcase_81 AC 514 ms
6,112 KB
testcase_82 AC 379 ms
5,192 KB
testcase_83 AC 408 ms
5,628 KB
testcase_84 AC 333 ms
5,080 KB
testcase_85 AC 37 ms
4,376 KB
testcase_86 AC 326 ms
4,748 KB
testcase_87 AC 458 ms
5,900 KB
testcase_88 AC 187 ms
4,376 KB
testcase_89 AC 388 ms
5,484 KB
testcase_90 AC 171 ms
4,380 KB
testcase_91 AC 408 ms
5,576 KB
権限があれば一括ダウンロードができます

ソースコード

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));
        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; // magic
            }
            dp[i+1] = acc + d[i];
        }
        // output
        cout << dp[n] << endl;
    }
    return 0;
}
0