結果

問題 No.409 ダイエット
ユーザー umimelumimel
提出日時 2023-01-31 23:50:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,636 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 172,132 KB
実行使用メモリ 7,580 KB
最終ジャッジ日時 2023-09-13 15:19:28
合計ジャッジ時間 5,907 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,500 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 15 ms
5,112 KB
testcase_56 AC 26 ms
7,428 KB
testcase_57 AC 31 ms
7,580 KB
testcase_58 AC 14 ms
4,976 KB
testcase_59 AC 20 ms
5,960 KB
testcase_60 AC 13 ms
4,984 KB
testcase_61 AC 28 ms
6,960 KB
testcase_62 AC 29 ms
7,432 KB
testcase_63 AC 27 ms
7,020 KB
testcase_64 AC 16 ms
5,172 KB
testcase_65 AC 30 ms
7,336 KB
testcase_66 AC 31 ms
7,488 KB
testcase_67 AC 23 ms
6,432 KB
testcase_68 AC 20 ms
5,700 KB
testcase_69 AC 27 ms
6,960 KB
testcase_70 AC 33 ms
6,760 KB
testcase_71 AC 18 ms
5,316 KB
testcase_72 AC 38 ms
7,420 KB
testcase_73 AC 37 ms
7,296 KB
testcase_74 AC 24 ms
5,752 KB
testcase_75 AC 36 ms
7,320 KB
testcase_76 AC 26 ms
5,900 KB
testcase_77 AC 19 ms
4,856 KB
testcase_78 AC 20 ms
5,380 KB
testcase_79 AC 16 ms
4,848 KB
testcase_80 AC 37 ms
7,224 KB
testcase_81 AC 36 ms
6,964 KB
testcase_82 AC 27 ms
5,904 KB
testcase_83 AC 29 ms
6,180 KB
testcase_84 AC 24 ms
5,616 KB
testcase_85 AC 4 ms
4,376 KB
testcase_86 AC 24 ms
5,700 KB
testcase_87 AC 32 ms
6,720 KB
testcase_88 AC 14 ms
4,592 KB
testcase_89 AC 28 ms
6,164 KB
testcase_90 AC 14 ms
4,380 KB
testcase_91 AC 31 ms
6,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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++){
        add({B-2*B*i-2*A, B*i*i-B*i+2*A*i+2*dp[i-1]+2*D[i]});
        dp[i] = (B*i*i+query(i))/2;
    }

    cout << dp[N] << endl;
}
0