結果

問題 No.409 ダイエット
ユーザー たこしたこし
提出日時 2018-09-26 21:52:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 2,274 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 164,824 KB
実行使用メモリ 8,024 KB
最終ジャッジ日時 2024-04-20 08:47:27
合計ジャッジ時間 7,354 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 3 ms
5,376 KB
testcase_41 AC 3 ms
5,376 KB
testcase_42 AC 3 ms
5,376 KB
testcase_43 AC 3 ms
5,376 KB
testcase_44 AC 3 ms
5,376 KB
testcase_45 AC 3 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 3 ms
5,376 KB
testcase_49 AC 3 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 3 ms
5,376 KB
testcase_52 AC 3 ms
5,376 KB
testcase_53 AC 3 ms
5,376 KB
testcase_54 AC 3 ms
5,376 KB
testcase_55 AC 32 ms
5,632 KB
testcase_56 AC 56 ms
7,808 KB
testcase_57 AC 62 ms
8,024 KB
testcase_58 AC 27 ms
5,376 KB
testcase_59 AC 40 ms
6,272 KB
testcase_60 AC 25 ms
5,376 KB
testcase_61 AC 55 ms
7,424 KB
testcase_62 AC 58 ms
7,680 KB
testcase_63 AC 55 ms
7,296 KB
testcase_64 AC 31 ms
5,504 KB
testcase_65 AC 59 ms
7,552 KB
testcase_66 AC 62 ms
7,884 KB
testcase_67 AC 47 ms
6,784 KB
testcase_68 AC 39 ms
6,144 KB
testcase_69 AC 54 ms
7,424 KB
testcase_70 AC 82 ms
7,296 KB
testcase_71 AC 46 ms
5,632 KB
testcase_72 AC 100 ms
7,936 KB
testcase_73 AC 93 ms
7,552 KB
testcase_74 AC 58 ms
6,016 KB
testcase_75 AC 93 ms
7,424 KB
testcase_76 AC 66 ms
6,272 KB
testcase_77 AC 46 ms
5,504 KB
testcase_78 AC 50 ms
5,632 KB
testcase_79 AC 41 ms
5,376 KB
testcase_80 AC 94 ms
7,756 KB
testcase_81 AC 91 ms
7,552 KB
testcase_82 AC 68 ms
6,528 KB
testcase_83 AC 74 ms
6,784 KB
testcase_84 AC 61 ms
6,144 KB
testcase_85 AC 9 ms
5,376 KB
testcase_86 AC 60 ms
6,016 KB
testcase_87 AC 82 ms
7,040 KB
testcase_88 AC 35 ms
5,376 KB
testcase_89 AC 70 ms
6,528 KB
testcase_90 AC 33 ms
5,376 KB
testcase_91 AC 74 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <cstdio>
#include <string>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

template< class T >
struct ConvexHullTrickAddQueryMonotone
{
  deque< pair< T, T > > L;
  int isdec;
 
  ConvexHullTrickAddQueryMonotone() : isdec(-1) {}
 
  inline T getX(const pair< T, T > &a, const T &x)
  {
    return (a.first * x + a.second);
  }
 
  inline bool check(const pair< T, T > &a, const pair< T, T > &b, const pair< T, T > &c)
  {
    return ((b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first));
  }
 
  inline bool empty() { return (L.empty()); }
 
  void add(T a, T b)
  {
    pair< T, T > line(a, b);
 
    if(!L.empty() && L.back().first == a) {
      line.second = min(line.second, L.back().second);
      L.pop_back();
    }
    while(L.size() >= 2 && check(L[L.size() - 2], L.back(), line)) L.pop_back();
    L.emplace_back(line);
 
  }
 
  T getMinimumQuery(T x)
  {
    int low = -1, high = (int) L.size() - 1;
    while(high - low > 1) {
      int mid = (low + high) >> 1;
      if((getX(L[mid], x) >= getX(L[mid + 1], x))) low = mid;
      else high = mid;
    }
    return (getX(L[high], x));
  }
 
  T getMinimumQueryMonotone(T x)
  {
    while(L.size() >= 2 && getX(L[0], x) >= getX(L[1], x)) {
      L.pop_front();
    }
    return (getX(L[0], x));
  }
 
};

const int MAX_N = 300005;
int N, A, B, W;
int D[MAX_N];
int dp[MAX_N];

signed main()
{
  cin >> N >> A >> B >> W;
  for(int i = 0; i < N; i++) {
    cin >> D[i];
  }

  dp[0] = 0;
  
  ConvexHullTrickAddQueryMonotone<int> cht;

  cht.add(0, 0);

  for(int i = 1; i <= N; i++) {
    dp[i] = cht.getMinimumQueryMonotone(i) - A*(i-1) + (i-1)*i/2*B + D[i-1];
    cht.add(-i*B, dp[i] + i*A + (i+1)*i/2*B);
    //cerr << dp[i] << " " << cht.get(i-1) << " " << D[i-1] << endl;
  }

  int ans = 114514191981036436;
  for(int i = 0; i < N+1; i++) {
    //cerr << i << " " << dp[i] << endl;
    ans = min(ans, dp[i] + (-(N-i)*A + (N-i)*(N-i+1)/2*B));
  }

  cout << ans+W << endl;

  return 0;
}
0