結果
| 問題 |
No.409 ダイエット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-01-31 23:23:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,636 bytes |
| コンパイル時間 | 1,784 ms |
| コンパイル使用メモリ | 175,468 KB |
| 実行使用メモリ | 7,708 KB |
| 最終ジャッジ日時 | 2024-06-30 23:43:08 |
| 合計ジャッジ時間 | 5,335 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 WA * 67 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;
deque<pll> deq;
ll N, A, B, W;
bool check(pll f1, pll f2, pll f3){
return (f2.fi-f1.fi)*(f3.se-f2.se) >= (f2.se-f1.se)*(f3.fi-f2.fi);
}
void add(pll conf2){
while((ll)deq.size()>=2){
pll conf1 = deq.back();
deq.pop_back();
pll conf0 = deq.back();
if(!check(conf0, conf1, conf2)){
deq.push_back(conf1);
break;
}
}
deq.push_back(conf2);
}
ll f(pll coef, ll x){ return (coef.fi*x + coef.se);}
ll query(ll x){
while((ll)deq.size()>=2){
pll coef0 = deq.front();
deq.pop_front();
pll coef1 = deq.front();
deq.pop_front();
if(f(coef0, x) >= f(coef1, x)){
deq.push_front(coef1);
}else{
deq.push_front(coef1);
deq.push_front(coef0);
break;
}
}
return f(deq.front(), x);
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> N >> A >> B >> W;
vector<ll> D(N+1);
for(ll i=1; i<=N; i++) cin >> D[i];
vector<ll> dp(N+1);
dp[0] = W;
add({B-2*A, 2*W});
for(ll i=1; i<=N; i++){
dp[i] = (B*i*i+query(i))/2;
add({B-2*B*i-2*A, B*i*i-B*i+2*A*i+2*dp[i-1]+2*D[i]});
}
cout << dp[N] << endl;
}