結果

問題 No.409 ダイエット
ユーザー vjudge1vjudge1
提出日時 2024-11-10 18:07:14
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 5,315 bytes
コンパイル時間 5,393 ms
コンパイル使用メモリ 278,892 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2024-11-10 18:07:23
合計ジャッジ時間 7,710 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 2 ms
5,248 KB
testcase_12 AC 2 ms
5,248 KB
testcase_13 AC 1 ms
5,248 KB
testcase_14 AC 2 ms
5,248 KB
testcase_15 AC 2 ms
5,248 KB
testcase_16 AC 2 ms
5,248 KB
testcase_17 AC 2 ms
5,248 KB
testcase_18 AC 2 ms
5,248 KB
testcase_19 AC 2 ms
5,248 KB
testcase_20 AC 2 ms
5,248 KB
testcase_21 AC 2 ms
5,248 KB
testcase_22 AC 2 ms
5,248 KB
testcase_23 AC 2 ms
5,248 KB
testcase_24 AC 1 ms
5,248 KB
testcase_25 AC 2 ms
5,248 KB
testcase_26 AC 2 ms
5,248 KB
testcase_27 AC 2 ms
5,248 KB
testcase_28 AC 2 ms
5,248 KB
testcase_29 AC 2 ms
5,248 KB
testcase_30 AC 2 ms
5,248 KB
testcase_31 AC 2 ms
5,248 KB
testcase_32 AC 2 ms
5,248 KB
testcase_33 AC 3 ms
5,248 KB
testcase_34 AC 2 ms
5,248 KB
testcase_35 AC 2 ms
5,248 KB
testcase_36 AC 3 ms
5,248 KB
testcase_37 AC 2 ms
5,248 KB
testcase_38 AC 3 ms
5,248 KB
testcase_39 AC 2 ms
5,248 KB
testcase_40 AC 4 ms
5,248 KB
testcase_41 AC 3 ms
5,248 KB
testcase_42 AC 2 ms
5,248 KB
testcase_43 AC 3 ms
5,248 KB
testcase_44 AC 3 ms
5,248 KB
testcase_45 AC 2 ms
5,248 KB
testcase_46 AC 2 ms
5,248 KB
testcase_47 AC 2 ms
5,248 KB
testcase_48 AC 3 ms
5,248 KB
testcase_49 AC 2 ms
5,248 KB
testcase_50 AC 2 ms
5,248 KB
testcase_51 AC 2 ms
5,248 KB
testcase_52 AC 2 ms
5,248 KB
testcase_53 AC 2 ms
5,248 KB
testcase_54 AC 3 ms
5,248 KB
testcase_55 AC 16 ms
6,144 KB
testcase_56 AC 31 ms
8,704 KB
testcase_57 AC 29 ms
8,960 KB
testcase_58 AC 13 ms
5,632 KB
testcase_59 AC 19 ms
6,784 KB
testcase_60 AC 14 ms
5,504 KB
testcase_61 AC 26 ms
8,192 KB
testcase_62 AC 28 ms
8,832 KB
testcase_63 AC 26 ms
8,192 KB
testcase_64 AC 16 ms
6,016 KB
testcase_65 AC 30 ms
8,448 KB
testcase_66 AC 30 ms
8,832 KB
testcase_67 AC 23 ms
7,552 KB
testcase_68 AC 20 ms
6,656 KB
testcase_69 AC 27 ms
8,064 KB
testcase_70 AC 34 ms
7,808 KB
testcase_71 AC 20 ms
5,888 KB
testcase_72 AC 38 ms
8,768 KB
testcase_73 AC 38 ms
8,320 KB
testcase_74 AC 23 ms
6,400 KB
testcase_75 AC 37 ms
8,320 KB
testcase_76 AC 26 ms
7,040 KB
testcase_77 AC 19 ms
5,632 KB
testcase_78 AC 20 ms
6,144 KB
testcase_79 AC 16 ms
5,632 KB
testcase_80 AC 37 ms
8,576 KB
testcase_81 AC 37 ms
8,320 KB
testcase_82 AC 26 ms
7,040 KB
testcase_83 AC 29 ms
7,296 KB
testcase_84 AC 25 ms
6,784 KB
testcase_85 AC 5 ms
5,248 KB
testcase_86 AC 23 ms
6,528 KB
testcase_87 AC 31 ms
7,808 KB
testcase_88 AC 15 ms
5,248 KB
testcase_89 AC 29 ms
7,040 KB
testcase_90 AC 14 ms
5,248 KB
testcase_91 AC 31 ms
7,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:13: warning: "assert" redefined
   13 | #define assert(...) 42
      | 
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/cassert:44,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/x86_64-pc-linux-gnu/bits/stdc++.h:106,
                 from main.cpp:6:
/usr/include/assert.h:92: note: this is the location of the previous definition
   92 | #  define assert(expr)                                                  \
      | 

ソースコード

diff #

/**
  * created     : 10.11.2024 15:37:06
  * author      : wzj33300
  */

#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include <algo/debug.h>
#else
#define debug(...) 42
#define assert(...) 42
#endif

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using db = long double;  // or double, if TL is tight
using str = string;      // yay python!

// pairs
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
#define fi first
#define se second

// ^ lol this makes everything look weird but I'll try it
template <class T>
using vc = vector<T>;
template <class T, size_t SZ>
using AR = array<T, SZ>;
using vi = vc<int>;
using vb = vc<bool>;
using vl = vc<ll>;
using vd = vc<db>;
using vs = vc<str>;
using vpi = vc<pi>;
using vpl = vc<pl>;
using vpd = vc<pd>;

// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)

#define rep_subset(t, s) \
  for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))

#define lb lower_bound
#define ub upper_bound
template <class T>
int lwb(vc<T> &a, const T &b) {
  return int(lb(all(a), b) - bg(a));
}
template <class T>
int upb(vc<T> &a, const T &b) {
  return int(ub(all(a), b) - bg(a));
}
// const int MOD = 998244353;  // 1e9+7;
const int Big = 1e9;  // not too close to INT_MAX
const ll BIG = 1e18;  // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4]{1, 0, -1, 0}, dy[4]{0, 1, 0, -1};  // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

int pct(int x) { return __builtin_popcount(x); }
int pct(u32 x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int pct(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <class T>
bool ckmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}  // set a = min(a,b)
template <class T>
bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}  // set a = max(a,b)

template <class T, class U>
T fstTrue(T lo, T hi, U f) {
  ++hi;
  assert(lo <= hi);  // assuming f is increasing
  while (lo < hi) {  // find first index such that f is true
    T mid = lo + (hi - lo) / 2;
    f(mid) ? hi = mid : lo = mid + 1;
  }
  return lo;
}
template <class T, class U>
T lstTrue(T lo, T hi, U f) {
  --lo;
  assert(lo <= hi);  // assuming f is decreasing
  while (lo < hi) {  // find first index such that f is true
    T mid = lo + (hi - lo + 1) / 2;
    f(mid) ? lo = mid : hi = mid - 1;
  }
  return lo;
}

// signed main() {
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll A, B, w;
  cin >> n >> A >> B >> w;
  vl D(n + 2), f(n + 2, BIG);
  for (int i = 1; i <= n; i++) cin >> D[i];
  auto X = [&](int j) -> ll { return j; };
  auto Y = [&](int j) -> ll { return f[j] + 1ll * j * (j + 1) / 2 * B + A * j; };
  auto slope = [&](int i, int j) -> db { return db(Y(i) - Y(j)) / (X(i) - X(j)); };

  f[0] = 0;
  std::vector<int> Q(n + 2);
  int h = 0, t = -1;
  Q[++t] = 0;
  for (int i = 1; i <= n + 1; i++) {
    while (t > h && slope(Q[h], Q[h + 1]) <= B * i) ++h;
    int j = Q[h];
    debug(j);
    // int from;
    // for (int j = 0; j < i; j++)
    //   if (ckmin(f[i], f[j] + B * (i - j - 1) * (i - j) / 2 - A * (i - j - 1) + D[i])) from = j;
    // debug(from);
    f[i] = f[j] + B * (i - j - 1) * (i - j) / 2 - A * (i - j - 1) + D[i];
    while (t > h && slope(Q[t - 1], Q[t]) >= slope(Q[t], i)) --t;
    Q[++t] = i;
  }
  debug(f);
  cout << f[n + 1] + w << '\n';
  return 0;
}

/*
[from]: 0
[from]: 0
[from]: 0
[from]: 2
[from]: 3
[from]: 3
[from]: 5
[from]: 6
[f]: {0, 10, 11, 17, 30, 27, 30, 36, 32}
*/
0