結果
問題 |
No.409 ダイエット
|
ユーザー |
|
提出日時 | 2023-01-31 22:59:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,430 bytes |
コンパイル時間 | 1,720 ms |
コンパイル使用メモリ | 175,832 KB |
実行使用メモリ | 14,464 KB |
最終ジャッジ日時 | 2024-06-30 23:29:11 |
合計ジャッジ時間 | 6,246 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 80 |
ソースコード
#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<tuple<ll, ll, ll>> deq; ll N, A, B, W; void add(ll a, ll b, ll c){ deq.push_back({a, b, c}); } ll f(tuple<ll, ll, ll> coef, ll x){ ll a = get<0>(coef); ll b = get<1>(coef); ll c = get<2>(coef); return (a*x*x + b*x+c)/2; } ll query(ll x){ while(deq.size()>=2){ tuple<ll, ll, ll> coef0 = deq.front(); deq.pop_front(); tuple<ll, ll, ll> 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, B-2*A, 2*W); for(ll i=1; i<=N; i++){ dp[i] = query(i); add(B, 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; }