結果

問題 No.409 ダイエット
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2017-01-08 19:25:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,319 bytes
コンパイル時間 1,493 ms
コンパイル使用メモリ 166,712 KB
実行使用メモリ 10,616 KB
最終ジャッジ日時 2023-09-08 17:16:50
合計ジャッジ時間 6,517 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,680 KB
testcase_01 AC 2 ms
7,536 KB
testcase_02 AC 3 ms
7,628 KB
testcase_03 AC 2 ms
7,456 KB
testcase_04 AC 2 ms
7,440 KB
testcase_05 AC 2 ms
7,468 KB
testcase_06 AC 2 ms
7,464 KB
testcase_07 AC 2 ms
7,596 KB
testcase_08 AC 2 ms
7,672 KB
testcase_09 AC 3 ms
7,544 KB
testcase_10 AC 3 ms
7,440 KB
testcase_11 AC 3 ms
7,464 KB
testcase_12 AC 2 ms
7,548 KB
testcase_13 AC 2 ms
7,548 KB
testcase_14 AC 2 ms
7,456 KB
testcase_15 AC 2 ms
7,460 KB
testcase_16 AC 2 ms
7,504 KB
testcase_17 AC 2 ms
7,532 KB
testcase_18 AC 3 ms
7,536 KB
testcase_19 AC 3 ms
7,520 KB
testcase_20 AC 2 ms
7,456 KB
testcase_21 AC 2 ms
7,676 KB
testcase_22 AC 2 ms
7,592 KB
testcase_23 AC 2 ms
7,464 KB
testcase_24 AC 2 ms
7,552 KB
testcase_25 AC 2 ms
7,644 KB
testcase_26 AC 2 ms
7,552 KB
testcase_27 AC 2 ms
7,460 KB
testcase_28 AC 2 ms
7,468 KB
testcase_29 AC 2 ms
7,444 KB
testcase_30 AC 2 ms
7,452 KB
testcase_31 AC 2 ms
7,552 KB
testcase_32 AC 2 ms
7,460 KB
testcase_33 AC 3 ms
7,468 KB
testcase_34 AC 2 ms
7,528 KB
testcase_35 AC 2 ms
7,464 KB
testcase_36 AC 3 ms
7,484 KB
testcase_37 AC 3 ms
7,588 KB
testcase_38 AC 3 ms
7,552 KB
testcase_39 AC 2 ms
7,568 KB
testcase_40 AC 3 ms
7,648 KB
testcase_41 AC 2 ms
7,496 KB
testcase_42 AC 3 ms
7,480 KB
testcase_43 AC 3 ms
7,784 KB
testcase_44 AC 3 ms
7,488 KB
testcase_45 AC 3 ms
7,480 KB
testcase_46 AC 3 ms
7,476 KB
testcase_47 AC 3 ms
7,788 KB
testcase_48 AC 3 ms
7,700 KB
testcase_49 AC 2 ms
7,464 KB
testcase_50 AC 2 ms
7,696 KB
testcase_51 AC 3 ms
7,488 KB
testcase_52 AC 3 ms
7,576 KB
testcase_53 AC 3 ms
7,696 KB
testcase_54 AC 2 ms
7,528 KB
testcase_55 AC 15 ms
8,556 KB
testcase_56 AC 27 ms
10,316 KB
testcase_57 AC 29 ms
10,616 KB
testcase_58 AC 14 ms
8,504 KB
testcase_59 AC 19 ms
8,848 KB
testcase_60 AC 13 ms
8,320 KB
testcase_61 AC 26 ms
10,216 KB
testcase_62 AC 26 ms
10,184 KB
testcase_63 AC 26 ms
9,944 KB
testcase_64 AC 15 ms
8,508 KB
testcase_65 AC 28 ms
10,264 KB
testcase_66 AC 28 ms
10,484 KB
testcase_67 AC 21 ms
9,380 KB
testcase_68 AC 19 ms
8,880 KB
testcase_69 AC 26 ms
9,916 KB
testcase_70 AC 31 ms
9,712 KB
testcase_71 AC 18 ms
8,480 KB
testcase_72 AC 37 ms
10,376 KB
testcase_73 AC 36 ms
10,312 KB
testcase_74 AC 21 ms
8,744 KB
testcase_75 AC 35 ms
10,104 KB
testcase_76 AC 25 ms
8,980 KB
testcase_77 AC 19 ms
8,440 KB
testcase_78 AC 19 ms
8,584 KB
testcase_79 AC 16 ms
8,408 KB
testcase_80 AC 35 ms
10,464 KB
testcase_81 AC 35 ms
10,300 KB
testcase_82 AC 25 ms
9,068 KB
testcase_83 AC 28 ms
9,264 KB
testcase_84 AC 23 ms
8,788 KB
testcase_85 AC 4 ms
7,676 KB
testcase_86 AC 24 ms
8,888 KB
testcase_87 AC 31 ms
9,680 KB
testcase_88 AC 14 ms
8,268 KB
testcase_89 AC 27 ms
9,072 KB
testcase_90 AC 14 ms
8,132 KB
testcase_91 AC 29 ms
9,588 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:59:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   59 | main() {
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,b) for (int i=(a);i<(b);++i)
#define rrep(i,n) for (int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) cout<<(#_v)<<":";for(auto(_x):(_v)){cout<<" "<<(_x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int N, A, B, W;
int D[300010];
int deq[300010];
int dp[300010];

int a(int i) {
    return - i * B;
}

int b(int i) {
    return dp[i] + i * A + i * (i + 1) * B / 2;
}

int f(int i, int x) {
    return a(i) * x + b(i);
}

bool check(int f1, int f2, int f3) {
    int a1 = a(f1), b1 = b(f1);
    int a2 = a(f2), b2 = b(f2);
    int a3 = a(f3), b3 = b(f3);
    return (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a3 - a2);
}

main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    cin >> N >> A >> B >> W;
    rep(i, N) cin >> D[i];

    int s = 0, t = 1;
    deq[0] = 0;
    dp[0] = W;
    rep2(i, 1, N + 1) {
        dp[i] = D[i - 1] - (i - 1) * A + i * (i - 1) * B / 2 + f(deq[s], i);
        while (s + 1 < t && check(deq[t - 2], deq[t - 1], i)) t--;
        deq[t++] = i;
        while (s + 1 < t && f(deq[s], i + 1) >= f(deq[s + 1], i + 1)) s++;
    }

    int ans = inf;
    rep(i, N + 1) {
        chmin(ans, dp[i] - (N - i) * A + (N - i) * (N - i + 1) * B / 2);
    }
    cout << ans << endl;
}
0