結果
| 問題 | No.409 ダイエット |
| コンテスト | |
| ユーザー |
Yang33
|
| 提出日時 | 2018-01-22 15:55:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 2,000 ms |
| コード長 | 2,834 bytes |
| 記録 | |
| コンパイル時間 | 1,563 ms |
| コンパイル使用メモリ | 173,520 KB |
| 実行使用メモリ | 12,324 KB |
| 最終ジャッジ日時 | 2024-06-26 10:26:36 |
| 合計ジャッジ時間 | 5,668 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 92 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (LL(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2018/01/22 Problem: yukicoder409 / Link: __CONTEST_URL__ ----- */
/* ------問題------
-----問題ここまで----- */
/* -----解説等-----
----解説ここまで---- */
struct CHT{
typedef pair<LL,LL> PT;
typedef LL RT;
vector<PT> deq; // first * x + second
int s,t;
CHT(int n):s(0),t(0){ deq.resize(n); }
void add(RT a,RT b){ // a: 単調減少
const PT p(a,b);
while(s+1 < t && check(deq[t-2],deq[t-1],p)) t--;
deq[t++] = p;
}
RT incl_query(RT x){ // x: 単調増加
while(s+1 < t && f(deq[s],x) >= f(deq[s+1],x)) s++;
return f(deq[s],x);
}
RT query(RT x){ // 条件なし
RT low = s-1, high = t-1;
while(low+1<high) {
RT mid = (low+high)>>1;
if (isright(deq[mid], deq[mid+1], x)) low = mid;
else high = mid;
}
return f(deq[high], x);
}
private:
bool isright(const PT &p1,const PT &p2,RT x){
return (p1.second-p2.second) >= x * (p2.first-p1.first);
}
bool check(const PT &p1,const PT &p2,const PT &p3){
return (p2.first-p1.first)*(p3.second-p2.second) >= (p2.second-p1.second)*(p3.first-p2.first);
}
RT f(const PT &p,RT x){
return p.first*x + p.second;
}
};
LL N,A,B,W;
LL ans = 0LL;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> N >> A >> B >> W;
VL d(N+1);
FOR(i,0,N){
cin >> d[i];
}
CHT Q(N);
VL dp(N+2,0);
dp[0] = W;
// dp(i) := 食べてi日目を終える
FOR(i,0,N){ // i日目に食べる
Q.add(-B*i,dp[i] + B*(i*i-i)/2+ A*i);
dp[i+1] = B*(i*i+i)/2 + d[i] - A*i + (Q.query(i));
//debug(dp[i]);
}
ans = LINF;
FOR(i,0,N+1){ // i日目から食べてないのでストレスまみれ
ans = min(ans, dp[i] - A*(N-i) +B*(N-i)*(N-i+1)/2);
}
cout << ans << "\n";
return 0;
}
Yang33