結果

問題 No.409 ダイエット
ユーザー goodbatongoodbaton
提出日時 2017-02-13 10:39:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 75,300 KB
実行使用メモリ 9,232 KB
最終ジャッジ日時 2023-09-08 17:19:27
合計ジャッジ時間 5,310 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,676 KB
testcase_01 AC 2 ms
5,596 KB
testcase_02 AC 2 ms
5,496 KB
testcase_03 AC 2 ms
5,612 KB
testcase_04 AC 2 ms
5,608 KB
testcase_05 AC 2 ms
5,584 KB
testcase_06 AC 2 ms
5,728 KB
testcase_07 AC 2 ms
5,596 KB
testcase_08 AC 2 ms
5,592 KB
testcase_09 AC 2 ms
5,584 KB
testcase_10 AC 2 ms
5,596 KB
testcase_11 AC 2 ms
5,664 KB
testcase_12 AC 2 ms
5,640 KB
testcase_13 AC 2 ms
5,680 KB
testcase_14 AC 2 ms
5,612 KB
testcase_15 AC 2 ms
5,608 KB
testcase_16 AC 2 ms
5,672 KB
testcase_17 AC 2 ms
5,500 KB
testcase_18 AC 2 ms
5,608 KB
testcase_19 AC 2 ms
5,828 KB
testcase_20 AC 2 ms
5,612 KB
testcase_21 AC 2 ms
5,648 KB
testcase_22 AC 2 ms
5,592 KB
testcase_23 AC 2 ms
5,592 KB
testcase_24 AC 2 ms
5,608 KB
testcase_25 AC 2 ms
5,536 KB
testcase_26 AC 2 ms
5,500 KB
testcase_27 AC 2 ms
5,540 KB
testcase_28 AC 2 ms
5,580 KB
testcase_29 AC 2 ms
5,588 KB
testcase_30 AC 2 ms
5,596 KB
testcase_31 AC 2 ms
5,580 KB
testcase_32 AC 2 ms
5,524 KB
testcase_33 AC 2 ms
5,580 KB
testcase_34 AC 2 ms
5,500 KB
testcase_35 AC 2 ms
5,676 KB
testcase_36 AC 3 ms
5,880 KB
testcase_37 AC 2 ms
5,768 KB
testcase_38 AC 2 ms
5,548 KB
testcase_39 AC 2 ms
5,620 KB
testcase_40 AC 2 ms
5,616 KB
testcase_41 AC 2 ms
5,640 KB
testcase_42 AC 2 ms
5,624 KB
testcase_43 AC 2 ms
5,672 KB
testcase_44 AC 2 ms
5,552 KB
testcase_45 AC 2 ms
5,612 KB
testcase_46 AC 2 ms
5,612 KB
testcase_47 AC 2 ms
5,640 KB
testcase_48 AC 2 ms
5,612 KB
testcase_49 AC 2 ms
5,632 KB
testcase_50 AC 2 ms
5,624 KB
testcase_51 AC 2 ms
5,856 KB
testcase_52 AC 2 ms
5,548 KB
testcase_53 AC 2 ms
5,560 KB
testcase_54 AC 2 ms
5,760 KB
testcase_55 AC 17 ms
7,120 KB
testcase_56 AC 29 ms
8,076 KB
testcase_57 AC 32 ms
9,232 KB
testcase_58 AC 14 ms
6,920 KB
testcase_59 AC 21 ms
7,248 KB
testcase_60 AC 13 ms
6,744 KB
testcase_61 AC 28 ms
8,848 KB
testcase_62 AC 29 ms
9,072 KB
testcase_63 AC 29 ms
8,404 KB
testcase_64 AC 17 ms
6,964 KB
testcase_65 AC 32 ms
8,372 KB
testcase_66 AC 32 ms
8,928 KB
testcase_67 AC 24 ms
7,992 KB
testcase_68 AC 21 ms
7,396 KB
testcase_69 AC 28 ms
8,568 KB
testcase_70 AC 32 ms
8,256 KB
testcase_71 AC 19 ms
6,996 KB
testcase_72 AC 40 ms
9,232 KB
testcase_73 AC 39 ms
8,404 KB
testcase_74 AC 24 ms
7,464 KB
testcase_75 AC 39 ms
8,580 KB
testcase_76 AC 27 ms
7,680 KB
testcase_77 AC 20 ms
6,808 KB
testcase_78 AC 21 ms
7,220 KB
testcase_79 AC 18 ms
6,848 KB
testcase_80 AC 39 ms
8,848 KB
testcase_81 AC 38 ms
8,428 KB
testcase_82 AC 28 ms
7,668 KB
testcase_83 AC 29 ms
7,820 KB
testcase_84 AC 26 ms
7,152 KB
testcase_85 AC 5 ms
6,028 KB
testcase_86 AC 25 ms
7,168 KB
testcase_87 AC 33 ms
8,284 KB
testcase_88 AC 15 ms
6,524 KB
testcase_89 AC 30 ms
7,244 KB
testcase_90 AC 14 ms
6,380 KB
testcase_91 AC 31 ms
7,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 300010

int n;
ll a,b,w;
ll d[SIZE];
ll dp[SIZE];

ll f_a(int t){
  return - b * t;
}

ll f_b(int t){
  return dp[t] + a * t + b * ((ll)t*t + t)/2;
}

ll f(int t,int x){
  return f_a(t) * x + f_b(t);
}

bool check(int f1, int f2, int f3){
  return (f_a(f2)-f_a(f1)) * (f_b(f3)-f_b(f2)) >= (f_b(f2)-f_b(f1)) * (f_a(f3)-f_a(f2));
}

int main(){
  int deq[SIZE];
  
  scanf("%d%lld%lld%lld",&n,&a,&b,&w);

  for(int i=1;i<=n;i++){
    scanf("%lld",d+i);
  }
  
  d[n+1] = 0;

  dp[0] = w;

  int s=0, t=1;
  deq[0] = 0;

  for(int i=1;i<=n+1;i++){
    while(s+1 < t && f(deq[s], i) >= f(deq[s+1],i)) s++;

    dp[i] = a * (1-i) + b * ((ll)i*i - i)/2 + d[i] + f(deq[s],i);
    
    while(s+1 < t && check(deq[t-2], deq[t-1], i)) t--;

    deq[t++] = i;
  }

  printf("%lld\n",dp[n+1]);
  
  return 0;
}
0