結果

問題 No.409 ダイエット
ユーザー mayoko_mayoko_
提出日時 2016-08-06 01:11:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,798 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 99,164 KB
実行使用メモリ 7,516 KB
最終ジャッジ日時 2023-09-08 16:55:55
合計ジャッジ時間 4,916 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 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 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,384 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 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,376 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 15 ms
5,084 KB
testcase_56 AC 25 ms
6,536 KB
testcase_57 AC 28 ms
7,516 KB
testcase_58 AC 13 ms
4,884 KB
testcase_59 AC 18 ms
5,352 KB
testcase_60 AC 12 ms
4,580 KB
testcase_61 AC 24 ms
6,732 KB
testcase_62 AC 26 ms
7,204 KB
testcase_63 AC 25 ms
6,736 KB
testcase_64 AC 14 ms
4,832 KB
testcase_65 AC 27 ms
6,536 KB
testcase_66 AC 28 ms
7,212 KB
testcase_67 AC 22 ms
6,144 KB
testcase_68 AC 19 ms
5,396 KB
testcase_69 AC 25 ms
6,412 KB
testcase_70 AC 30 ms
6,472 KB
testcase_71 AC 17 ms
5,308 KB
testcase_72 AC 35 ms
7,220 KB
testcase_73 AC 34 ms
6,680 KB
testcase_74 AC 21 ms
5,616 KB
testcase_75 AC 34 ms
6,720 KB
testcase_76 AC 24 ms
5,948 KB
testcase_77 AC 17 ms
4,952 KB
testcase_78 AC 18 ms
5,356 KB
testcase_79 AC 15 ms
5,132 KB
testcase_80 AC 33 ms
6,980 KB
testcase_81 AC 33 ms
6,720 KB
testcase_82 AC 25 ms
5,944 KB
testcase_83 AC 26 ms
6,152 KB
testcase_84 AC 22 ms
5,352 KB
testcase_85 AC 4 ms
4,380 KB
testcase_86 AC 22 ms
5,352 KB
testcase_87 AC 30 ms
6,628 KB
testcase_88 AC 13 ms
4,376 KB
testcase_89 AC 26 ms
5,472 KB
testcase_90 AC 13 ms
4,380 KB
testcase_91 AC 29 ms
5,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 300300;
ll dp[MAXN];
int deq[MAXN];
int N, A, B, W;

bool check(int f1, int f2, int f3) {
    ll a1 = -(ll)B*f1, b1 = (ll)f1*A + ((ll)f1*f1+f1)/2 * B + dp[f1];
    ll a2 = -(ll)B*f2, b2 = (ll)f2*A + ((ll)f2*f2+f2)/2 * B + dp[f2];
    ll a3 = -(ll)B*f3, b3 = (ll)f3*A + ((ll)f3*f3+f3)/2 * B + dp[f3];
    return (a2-a1) * (b3-b2) >= (b2-b1) * (a3-a2);
}

ll f(int j, int x) {
    return -(ll)B*j*x + (ll)j*A + ((ll)j*j+j)/2*B + dp[j];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B >> W;
    vector<int> D(N);
    for (int i = 0; i < N; i++)
        cin >> D[i];
    dp[0] = 0;
    int s = 0, t = 1;
    deq[0] = 0;
    for (int i = 1; i <= N; i++) {
        while (s+1 < t && f(deq[s], i) >= f(deq[s+1], i)) s++;
        dp[i] = f(deq[s], i) + D[i-1] - (ll)(i-1)*A + ((ll)i*i-i)/2*B;
        // 末尾から最小値を取る可能性がなくなったものを取り除く
        while (s+1 < t && check(deq[t-2], deq[t-1], i)) t--;
        deq[t++] = i;
    }
    ll ans = 1ll<<60;
    for (int i = 0; i <= N; i++) {
        ll d = N-i;
        ans = min(ans, dp[i]+B*(d+1)*d/2 - A*d);
    }
    cout << ans+W << endl;
    return 0;
}
0