結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 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,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,384 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,508 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 18 ms
8,576 KB
testcase_56 AC 22 ms
4,676 KB
testcase_57 AC 34 ms
12,880 KB
testcase_58 AC 16 ms
8,152 KB
testcase_59 AC 22 ms
7,900 KB
testcase_60 AC 15 ms
8,720 KB
testcase_61 AC 30 ms
13,272 KB
testcase_62 AC 32 ms
13,100 KB
testcase_63 AC 31 ms
12,784 KB
testcase_64 AC 18 ms
7,580 KB
testcase_65 AC 34 ms
8,776 KB
testcase_66 AC 35 ms
12,704 KB
testcase_67 AC 26 ms
12,384 KB
testcase_68 AC 22 ms
9,000 KB
testcase_69 AC 32 ms
11,984 KB
testcase_70 AC 35 ms
12,056 KB
testcase_71 AC 20 ms
7,352 KB
testcase_72 AC 42 ms
12,268 KB
testcase_73 AC 42 ms
13,280 KB
testcase_74 AC 27 ms
11,996 KB
testcase_75 AC 40 ms
12,184 KB
testcase_76 AC 28 ms
12,716 KB
testcase_77 AC 21 ms
6,344 KB
testcase_78 AC 23 ms
11,800 KB
testcase_79 AC 19 ms
7,332 KB
testcase_80 AC 39 ms
13,316 KB
testcase_81 AC 40 ms
13,376 KB
testcase_82 AC 31 ms
11,368 KB
testcase_83 AC 31 ms
13,140 KB
testcase_84 AC 26 ms
8,596 KB
testcase_85 AC 4 ms
4,376 KB
testcase_86 AC 26 ms
8,024 KB
testcase_87 AC 34 ms
11,664 KB
testcase_88 AC 15 ms
5,612 KB
testcase_89 AC 29 ms
6,400 KB
testcase_90 AC 14 ms
5,000 KB
testcase_91 AC 31 ms
6,304 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; //cerr << "*" << f[i] << ' ' << ptr << endl;
        long long another = f[i - 1] + d[i]; //cerr << "ANOTHER " << another << endl;
        Line d1 = {-1LL * i * b, another + 1LL * i * a + i * (i - 1LL) / 2 * b, 1e50};
        //cerr << d1.a << ' ' << d1.b << " LINE" << endl;
        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);
        //for (auto x : lines) cerr << x.lim << ' '; cerr << endl;
        f[i] = min(f[i], another);
    }
    //for (int i = 1; i <= n; ++i) cout << f[i] << ' '; cout << '\n';
    cout << f[n] + w << '\n';
    return 0;
}
0