結果

問題 No.409 ダイエット
ユーザー hashiryohashiryo
提出日時 2019-05-08 20:37:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 2,056 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 97,524 KB
実行使用メモリ 8,772 KB
最終ジャッジ日時 2023-09-14 17:24:22
合計ジャッジ時間 8,484 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 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,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 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 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 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,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 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,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 15 ms
5,232 KB
testcase_56 AC 22 ms
4,380 KB
testcase_57 AC 28 ms
7,420 KB
testcase_58 AC 14 ms
5,236 KB
testcase_59 AC 18 ms
5,160 KB
testcase_60 AC 13 ms
5,292 KB
testcase_61 AC 25 ms
7,464 KB
testcase_62 AC 26 ms
8,680 KB
testcase_63 AC 26 ms
8,320 KB
testcase_64 AC 15 ms
5,256 KB
testcase_65 AC 26 ms
5,124 KB
testcase_66 AC 28 ms
8,772 KB
testcase_67 AC 22 ms
8,228 KB
testcase_68 AC 18 ms
5,060 KB
testcase_69 AC 26 ms
7,400 KB
testcase_70 AC 30 ms
7,672 KB
testcase_71 AC 18 ms
5,192 KB
testcase_72 AC 36 ms
8,144 KB
testcase_73 AC 35 ms
8,200 KB
testcase_74 AC 23 ms
8,516 KB
testcase_75 AC 35 ms
7,792 KB
testcase_76 AC 25 ms
7,724 KB
testcase_77 AC 17 ms
4,380 KB
testcase_78 AC 20 ms
8,028 KB
testcase_79 AC 16 ms
5,068 KB
testcase_80 AC 35 ms
8,716 KB
testcase_81 AC 34 ms
7,392 KB
testcase_82 AC 26 ms
8,056 KB
testcase_83 AC 28 ms
7,852 KB
testcase_84 AC 23 ms
5,236 KB
testcase_85 AC 4 ms
4,376 KB
testcase_86 AC 22 ms
5,116 KB
testcase_87 AC 31 ms
7,460 KB
testcase_88 AC 13 ms
4,376 KB
testcase_89 AC 24 ms
4,376 KB
testcase_90 AC 13 ms
4,380 KB
testcase_91 AC 26 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = INT_MAX;
const ll MOD = 1e9+7;


template<typename T>
class ConvexHullTrick {
private:
    vector<pair<T, T> > lines;
    int head;
    bool check(pair<T, T> l1, pair<T, T> l2, pair<T, T> l3) {
        return (l3.second - l2.second) * (l2.first - l1.first) >= (l2.second - l1.second) * (l3.first - l2.first);
    }

    T f(int i, T x) {
        return lines[i].first * x + lines[i].second;
    }
public:
    ConvexHullTrick():head(0){}
    void insert(T a, T b) {
        pair<T, T> line(a, b);
        while (lines.size()-head >= 2 && check(*(lines.end() - 2), lines.back(), line))
            lines.pop_back();
        lines.emplace_back(line);
    }
    T getmin(T x) {
        while (lines.size() - head >= 2 && (f(head, x)>=f(head + 1, x)))
            ++head;
        return f(head, x);
    }
};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ll A,B,W;
  cin>>N>>A>>B>>W;
  ConvexHullTrick<ll> CHT;
  CHT.insert(-B,2*W);
  for(ll i=1;i<=N;i++){
    ll D;cin>>D;
    ll dp=(CHT.getmin(i)+B*i*i-2*A*(i-1)+2*D)/2;
    CHT.insert(-B*(1+2*i),B*(i+1)*i+2*A*i+2*dp);
  }
  cout<<(CHT.getmin(N+1)+B*(N+1)*(N+1)-2*A*(N))/2<<endl;
  return 0;
}
0