結果

問題 No.409 ダイエット
ユーザー gyouzasushigyouzasushi
提出日時 2022-05-25 14:37:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,599 bytes
コンパイル時間 2,014 ms
コンパイル使用メモリ 208,036 KB
実行使用メモリ 19,172 KB
最終ジャッジ日時 2023-10-20 19:12:08
合計ジャッジ時間 9,256 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 3 ms
4,348 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 4 ms
4,348 KB
testcase_46 AC 3 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 4 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 4 ms
4,348 KB
testcase_51 AC 3 ms
4,348 KB
testcase_52 AC 3 ms
4,348 KB
testcase_53 AC 4 ms
4,348 KB
testcase_54 AC 3 ms
4,348 KB
testcase_55 AC 62 ms
10,724 KB
testcase_56 AC 52 ms
7,820 KB
testcase_57 AC 121 ms
19,172 KB
testcase_58 AC 54 ms
9,932 KB
testcase_59 AC 75 ms
11,516 KB
testcase_60 AC 48 ms
9,404 KB
testcase_61 AC 116 ms
17,060 KB
testcase_62 AC 120 ms
18,644 KB
testcase_63 AC 112 ms
16,532 KB
testcase_64 AC 59 ms
10,196 KB
testcase_65 WA -
testcase_66 AC 121 ms
18,116 KB
testcase_67 AC 91 ms
15,212 KB
testcase_68 AC 75 ms
11,516 KB
testcase_69 AC 105 ms
16,004 KB
testcase_70 AC 132 ms
16,268 KB
testcase_71 AC 70 ms
10,460 KB
testcase_72 AC 154 ms
19,172 KB
testcase_73 WA -
testcase_74 AC 90 ms
12,308 KB
testcase_75 AC 141 ms
16,268 KB
testcase_76 AC 106 ms
13,892 KB
testcase_77 AC 69 ms
8,876 KB
testcase_78 AC 81 ms
11,780 KB
testcase_79 AC 62 ms
9,404 KB
testcase_80 AC 149 ms
18,116 KB
testcase_81 AC 146 ms
15,740 KB
testcase_82 AC 104 ms
13,892 KB
testcase_83 AC 114 ms
14,420 KB
testcase_84 AC 94 ms
10,724 KB
testcase_85 AC 11 ms
4,388 KB
testcase_86 AC 94 ms
10,988 KB
testcase_87 AC 133 ms
16,268 KB
testcase_88 AC 52 ms
7,820 KB
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        os << v[i];
        if (i < int(v.size()) - 1) os << ' ';
    }
    return os;
}
// DynamicLiChaoTree<ll> LCT(ll min_index,ll max_index); などする
// xの動きうる最大範囲が[min_index,max_index)
// void add_line(T a,T b): 直線 ax+b を追加
// void add_segment_line(T Llim,T Rlim,T a,T b): [Llim,Rlim]の線分 ax+b を追加
// T get(T x): min(ax+b) を返す

template <typename T>
struct DynamicLiChaoTree {
private:
    struct Line {
        T slope, intercept;
        Line() : slope(0), intercept(numeric_limits<T>::max()) {
        }
        Line(T a, T b) : slope(a), intercept(b) {
        }
        T f(T x) {
            return slope * x + intercept;
        }
    };

    struct node {
        Line line;
        node *left, *right;

        node(Line line) : line(line), left(nullptr), right(nullptr) {
        }
    };

    const long long min_index, max_index;
    node* root;

    node* add_line(node*& t, long long l, long long r, Line line) const {
        if (l == r) return nullptr;
        if (!t) {
            t = new node(line);
            return t;
        }
        long long m = (l + r) >> 1;
        bool L = (line.f(l) <= t->line.f(l));
        bool M = (line.f(m) <= t->line.f(m));
        bool R = (line.f(r) <= t->line.f(r));
        if (L && R) {
            t->line = line;
            return t;
        }
        if (!L && !R) {
            return t;
        }
        if (M) {
            swap(t->line, line);
        }
        if (L != M) {
            t->left = add_line(t->left, l, m, line);
        } else {
            t->right = add_line(t->right, m + 1, r, line);
        }
        return t;
    }

    node* add_segment_line(node*& t, long long Llim, long long Rlim,
                           long long l, long long r, Line line) {
        if (r <= Llim || Rlim <= l) return t;
        if (Llim <= l && r <= Rlim) return add_line(t, l, r, line);
        if (t == nullptr) t = new node(Line());
        long long m = (l + r) >> 1;
        t->left = add_segment_line(t->left, Llim, Rlim, l, m, line);
        t->right = add_segment_line(t->right, Llim, Rlim, m, r, line);
        return t;
    }

public:
    DynamicLiChaoTree(T min_index, T max_index)
        : min_index(min_index), max_index(max_index), root(nullptr) {
    }

    void add_line(T a, T b) {
        Line line = Line{a, b};
        add_line(root, min_index, max_index, line);
    }

    void add_segment_line(T Llim, T Rlim, T a, T b) {
        Line line = Line{a, b};
        add_segment_line(root, Llim, Rlim, min_index, max_index, line);
    }

    T get(long long x) {
        node* t = root;
        long long l = min_index, r = max_index;
        T ret = numeric_limits<T>::max();
        while (r - l > 0 && t != nullptr) {
            long long m = (l + r) >> 1;
            ret = min(ret, t->line.f(x));
            if (x < m) {
                r = m;
                t = t->left;
            } else {
                l = m;
                t = t->right;
            }
        }
        return ret;
    }
};
int main() {
    int n;
    ll a, b, w;
    cin >> n >> a >> b >> w;
    vector<ll> d(n);
    cin >> d;
    vector<ll> dp(n + 1, LINF);
    dp[0] = 0;
    DynamicLiChaoTree<ll> lct(0, 1001001);
    rep(i, n) {
        ll x = ll(i);
        lct.add_line(-b * x, dp[i] + (b * x * x - b * x) / 2);
        dp[i + 1] = lct.get(x) + (b * x * x + b * x) / 2 + d[i] + a;
    }
    ll ans = LINF;
    rep(i, n + 1) {
        chmin(ans, w + dp[i] - a * n + b * (n - i) * (n - i + 1) / 2);
    }
    cout << ans << '\n';
}
0