結果

問題 No.409 ダイエット
ユーザー Yang33Yang33
提出日時 2018-01-22 15:55:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 2,834 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 171,468 KB
実行使用メモリ 12,096 KB
最終ジャッジ日時 2023-09-08 17:38:20
合計ジャッジ時間 6,817 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 3 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 31 ms
7,452 KB
testcase_56 AC 28 ms
11,876 KB
testcase_57 AC 62 ms
12,064 KB
testcase_58 AC 26 ms
7,068 KB
testcase_59 AC 38 ms
8,716 KB
testcase_60 AC 24 ms
6,436 KB
testcase_61 AC 55 ms
11,164 KB
testcase_62 AC 58 ms
11,736 KB
testcase_63 AC 55 ms
10,824 KB
testcase_64 AC 29 ms
7,180 KB
testcase_65 AC 56 ms
11,072 KB
testcase_66 AC 62 ms
11,908 KB
testcase_67 AC 48 ms
9,952 KB
testcase_68 AC 39 ms
8,504 KB
testcase_69 AC 53 ms
10,604 KB
testcase_70 AC 58 ms
10,448 KB
testcase_71 AC 32 ms
6,952 KB
testcase_72 AC 70 ms
12,096 KB
testcase_73 AC 64 ms
11,268 KB
testcase_74 AC 39 ms
8,240 KB
testcase_75 AC 65 ms
11,212 KB
testcase_76 AC 47 ms
9,076 KB
testcase_77 AC 31 ms
6,960 KB
testcase_78 AC 35 ms
7,644 KB
testcase_79 AC 28 ms
6,724 KB
testcase_80 AC 66 ms
11,464 KB
testcase_81 AC 64 ms
11,196 KB
testcase_82 AC 47 ms
9,088 KB
testcase_83 AC 51 ms
9,660 KB
testcase_84 AC 42 ms
8,372 KB
testcase_85 AC 6 ms
4,380 KB
testcase_86 AC 41 ms
8,272 KB
testcase_87 AC 57 ms
10,408 KB
testcase_88 AC 24 ms
6,012 KB
testcase_89 AC 45 ms
9,104 KB
testcase_90 AC 22 ms
6,032 KB
testcase_91 AC 48 ms
9,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (LL(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/01/22  Problem: yukicoder409 / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


struct CHT{
    typedef pair<LL,LL> PT;
    typedef LL RT;
    vector<PT> deq; // first * x + second
    int s,t;
    CHT(int n):s(0),t(0){ deq.resize(n); }
    void add(RT a,RT b){  // a: 単調減少
        const PT p(a,b);
        while(s+1 < t && check(deq[t-2],deq[t-1],p)) t--;
        deq[t++] = p;
    }
    RT incl_query(RT x){  // x: 単調増加
        while(s+1 < t && f(deq[s],x) >= f(deq[s+1],x)) s++;
        return f(deq[s],x);
    }
    RT query(RT x){   // 条件なし
        RT low = s-1, high = t-1;
        while(low+1<high) {
            RT mid = (low+high)>>1;
            if (isright(deq[mid], deq[mid+1], x)) low = mid;
            else high = mid;
        }
        return f(deq[high], x);
    }
    
private:
    bool isright(const PT &p1,const PT &p2,RT x){
         return (p1.second-p2.second) >= x * (p2.first-p1.first);
    }
    bool check(const PT &p1,const PT &p2,const PT &p3){
        return (p2.first-p1.first)*(p3.second-p2.second) >= (p2.second-p1.second)*(p3.first-p2.first);
    }
    RT f(const PT &p,RT x){
        return p.first*x + p.second;
    }
};
LL N,A,B,W;

LL ans = 0LL;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N >> A >> B >> W;
	VL d(N+1);
	FOR(i,0,N){
		cin >> d[i];
	}
	CHT Q(N);
	VL dp(N+2,0);
	dp[0] = W;
	// dp(i) := 食べてi日目を終える 
	FOR(i,0,N){ //             i日目に食べる
		Q.add(-B*i,dp[i] + B*(i*i-i)/2+ A*i); 
		dp[i+1] = B*(i*i+i)/2 + d[i] - A*i + (Q.query(i));
		//debug(dp[i]);
	}
	ans = LINF;
	FOR(i,0,N+1){ // i日目から食べてないのでストレスまみれ
		ans = min(ans,  dp[i] - A*(N-i) +B*(N-i)*(N-i+1)/2);
	}
	cout << ans << "\n";

	return 0;
}
0