結果

問題 No.409 ダイエット
ユーザー yukudoyukudo
提出日時 2019-01-19 22:21:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 3,006 ms
コンパイル使用メモリ 150,576 KB
実行使用メモリ 8,148 KB
最終ジャッジ日時 2023-09-25 13:03:45
合計ジャッジ時間 8,776 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,372 KB
testcase_01 AC 2 ms
5,372 KB
testcase_02 AC 2 ms
5,436 KB
testcase_03 AC 2 ms
5,436 KB
testcase_04 AC 2 ms
5,384 KB
testcase_05 AC 2 ms
5,384 KB
testcase_06 AC 2 ms
5,700 KB
testcase_07 AC 2 ms
5,496 KB
testcase_08 AC 2 ms
5,436 KB
testcase_09 AC 2 ms
5,384 KB
testcase_10 AC 2 ms
5,496 KB
testcase_11 AC 2 ms
5,440 KB
testcase_12 AC 2 ms
5,384 KB
testcase_13 AC 2 ms
5,432 KB
testcase_14 AC 2 ms
5,700 KB
testcase_15 AC 2 ms
5,440 KB
testcase_16 AC 2 ms
5,380 KB
testcase_17 AC 2 ms
5,380 KB
testcase_18 AC 2 ms
5,704 KB
testcase_19 AC 2 ms
5,384 KB
testcase_20 AC 2 ms
5,372 KB
testcase_21 AC 2 ms
5,448 KB
testcase_22 AC 2 ms
5,384 KB
testcase_23 AC 2 ms
5,380 KB
testcase_24 AC 2 ms
5,372 KB
testcase_25 AC 2 ms
5,460 KB
testcase_26 AC 2 ms
5,368 KB
testcase_27 AC 2 ms
5,372 KB
testcase_28 AC 2 ms
5,524 KB
testcase_29 AC 2 ms
5,372 KB
testcase_30 AC 2 ms
5,432 KB
testcase_31 AC 2 ms
5,384 KB
testcase_32 AC 2 ms
5,372 KB
testcase_33 AC 2 ms
5,524 KB
testcase_34 AC 2 ms
5,416 KB
testcase_35 AC 3 ms
5,456 KB
testcase_36 AC 3 ms
5,404 KB
testcase_37 AC 3 ms
5,388 KB
testcase_38 AC 3 ms
5,444 KB
testcase_39 AC 3 ms
5,420 KB
testcase_40 AC 3 ms
5,516 KB
testcase_41 AC 3 ms
5,420 KB
testcase_42 AC 3 ms
5,388 KB
testcase_43 AC 3 ms
5,464 KB
testcase_44 AC 3 ms
5,456 KB
testcase_45 AC 3 ms
5,404 KB
testcase_46 AC 3 ms
5,444 KB
testcase_47 AC 3 ms
5,404 KB
testcase_48 AC 3 ms
5,408 KB
testcase_49 AC 3 ms
5,512 KB
testcase_50 AC 3 ms
5,524 KB
testcase_51 AC 3 ms
5,396 KB
testcase_52 AC 3 ms
5,512 KB
testcase_53 AC 3 ms
5,520 KB
testcase_54 AC 3 ms
5,480 KB
testcase_55 AC 29 ms
6,616 KB
testcase_56 AC 54 ms
8,024 KB
testcase_57 AC 58 ms
8,056 KB
testcase_58 AC 25 ms
6,416 KB
testcase_59 AC 37 ms
6,820 KB
testcase_60 AC 23 ms
6,232 KB
testcase_61 AC 51 ms
7,900 KB
testcase_62 AC 53 ms
7,908 KB
testcase_63 AC 51 ms
7,656 KB
testcase_64 AC 28 ms
6,500 KB
testcase_65 AC 54 ms
8,148 KB
testcase_66 AC 57 ms
8,120 KB
testcase_67 AC 43 ms
7,112 KB
testcase_68 AC 36 ms
6,780 KB
testcase_69 AC 50 ms
7,588 KB
testcase_70 AC 76 ms
7,500 KB
testcase_71 AC 43 ms
6,400 KB
testcase_72 AC 92 ms
8,000 KB
testcase_73 AC 86 ms
7,892 KB
testcase_74 AC 53 ms
6,652 KB
testcase_75 AC 85 ms
7,840 KB
testcase_76 AC 61 ms
7,180 KB
testcase_77 AC 42 ms
6,532 KB
testcase_78 AC 46 ms
6,500 KB
testcase_79 AC 38 ms
6,268 KB
testcase_80 AC 86 ms
7,920 KB
testcase_81 AC 84 ms
7,792 KB
testcase_82 AC 62 ms
6,884 KB
testcase_83 AC 68 ms
7,008 KB
testcase_84 AC 55 ms
6,824 KB
testcase_85 AC 8 ms
5,728 KB
testcase_86 AC 55 ms
6,720 KB
testcase_87 AC 75 ms
7,448 KB
testcase_88 AC 31 ms
6,432 KB
testcase_89 AC 65 ms
6,896 KB
testcase_90 AC 30 ms
6,244 KB
testcase_91 AC 69 ms
7,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


const int MAX_N = 312345;
ll D[MAX_N];
ll dp[MAX_N];

struct Line {
  ll a, b;
  ll f(ll x) { return a*x + b; }
};

bool check(Line l1, Line l2, Line l3) {
  return (l3.b-l2.b)*(l1.a-l2.a) <= (l2.b-l1.b)*(l2.a-l3.a);
}

int main2() {
  int N;
  ll A, B, W; cin >> N >> A >> B >> W;
  REP(i, N) { cin >> D[i]; }
  A *= 2; B *= 2; W *= 2;
  REP(i, N) D[i] *= 2;

  dp[0] = W;
  deque<Line> deq;
  REP(i, N) {
    Line line = (Line) {-i*B, dp[i] + i*A + B/2*i*i + i*B/2};
    while (deq.size() >= 2 && check(deq[deq.size()-2], deq[deq.size()-1], line))
      deq.pop_back();
    deq.push_back(line);
    while (deq.size() >= 2 && deq[0].f(i+1) >= deq[1].f(i+1)) deq.pop_front();
    ll val = deq[0].f(i+1);
    dp[i+1] = val + (D[i] - (i+1)*A + A + B/2*(i+1)*(i+1) - (i+1)*B/2);
  }

  ll ans = dp[N];
  for (int i = 0; i < N; i++) {
    chmin(ans, dp[i] - (N-i)*A + (ll)(N-i)*(N-i+1)/2*B);
  }
  cout << ans/2 << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}
0