結果

問題 No.409 ダイエット
ユーザー dnkdnk
提出日時 2016-08-06 00:27:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 148,572 KB
実行使用メモリ 13,100 KB
最終ジャッジ日時 2023-09-08 16:53:54
合計ジャッジ時間 5,713 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 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,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 19 ms
7,464 KB
testcase_56 AC 22 ms
4,468 KB
testcase_57 AC 35 ms
12,872 KB
testcase_58 AC 17 ms
7,180 KB
testcase_59 AC 23 ms
7,968 KB
testcase_60 AC 16 ms
7,208 KB
testcase_61 AC 31 ms
12,272 KB
testcase_62 AC 33 ms
12,528 KB
testcase_63 AC 32 ms
12,416 KB
testcase_64 AC 18 ms
7,624 KB
testcase_65 AC 34 ms
8,656 KB
testcase_66 AC 34 ms
13,100 KB
testcase_67 AC 26 ms
12,052 KB
testcase_68 AC 23 ms
8,004 KB
testcase_69 AC 30 ms
13,000 KB
testcase_70 AC 34 ms
12,988 KB
testcase_71 AC 21 ms
7,264 KB
testcase_72 AC 42 ms
12,460 KB
testcase_73 AC 42 ms
12,328 KB
testcase_74 AC 25 ms
12,384 KB
testcase_75 AC 39 ms
12,760 KB
testcase_76 AC 30 ms
11,820 KB
testcase_77 AC 20 ms
6,140 KB
testcase_78 AC 23 ms
12,636 KB
testcase_79 AC 18 ms
8,200 KB
testcase_80 AC 40 ms
11,932 KB
testcase_81 AC 41 ms
12,096 KB
testcase_82 AC 31 ms
11,520 KB
testcase_83 AC 32 ms
12,692 KB
testcase_84 AC 27 ms
8,136 KB
testcase_85 AC 4 ms
4,376 KB
testcase_86 AC 27 ms
8,140 KB
testcase_87 AC 36 ms
11,960 KB
testcase_88 AC 15 ms
5,580 KB
testcase_89 AC 29 ms
6,196 KB
testcase_90 AC 14 ms
4,764 KB
testcase_91 AC 31 ms
6,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int N = (int) 3e5 + 1;
int a, b, w, d[N], n;
long long f[N];

struct Line {
    long long a, b; // ax + b
    double lim;

    double cut(const Line &other) {
        return -(b - other.b) / (double) (a - other.a);
    }

    long long x(int z) {
        return a * z + b;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> a >> b >> w;
    for (int i = 1; i <= n; ++i) cin >> d[i];
    if (b == 0) {
        cout << w - 1LL * a * n << endl;
        return 0;
    }
    vector<Line> lines;
    lines.push_back({0, 0, 1e50});
    int ptr = 0;
    for (int i = 1; i <= n; ++i) {
        ptr = min(ptr, (int) lines.size() - 1);
        while (i > lines[ptr].lim) ++ptr;
        f[i] = lines[ptr].x(i) - 1LL * i * a + i * (i + 1LL) / 2 * b;
        long long another = f[i - 1] + d[i];
        Line d1 = {-1LL * i * b, another + 1LL * i * a + i * (i - 1LL) / 2 * b, 1e50};
        while (lines.size() > 1 && d1.cut(lines[lines.size() - 1]) <= d1.cut(lines[lines.size() - 2])) lines.pop_back();
        lines.back().lim = d1.cut(lines.back());
        lines.push_back(d1);
        f[i] = min(f[i], another);
    }
    cout << f[n] + w << '\n';
    return 0;
}
0