結果
問題 | No.409 ダイエット |
ユーザー | 🍡yurahuna |
提出日時 | 2017-01-08 19:25:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 2,319 bytes |
コンパイル時間 | 1,683 ms |
コンパイル使用メモリ | 168,532 KB |
実行使用メモリ | 10,456 KB |
最終ジャッジ日時 | 2024-06-26 10:06:41 |
合計ジャッジ時間 | 5,115 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,524 KB |
testcase_01 | AC | 3 ms
7,516 KB |
testcase_02 | AC | 3 ms
7,520 KB |
testcase_03 | AC | 3 ms
7,520 KB |
testcase_04 | AC | 2 ms
7,520 KB |
testcase_05 | AC | 3 ms
7,648 KB |
testcase_06 | AC | 3 ms
7,648 KB |
testcase_07 | AC | 3 ms
7,520 KB |
testcase_08 | AC | 2 ms
7,644 KB |
testcase_09 | AC | 3 ms
7,524 KB |
testcase_10 | AC | 3 ms
7,648 KB |
testcase_11 | AC | 3 ms
7,648 KB |
testcase_12 | AC | 2 ms
7,644 KB |
testcase_13 | AC | 2 ms
7,524 KB |
testcase_14 | AC | 3 ms
7,520 KB |
testcase_15 | AC | 3 ms
7,520 KB |
testcase_16 | AC | 3 ms
7,644 KB |
testcase_17 | AC | 2 ms
7,520 KB |
testcase_18 | AC | 2 ms
7,520 KB |
testcase_19 | AC | 2 ms
7,516 KB |
testcase_20 | AC | 3 ms
7,524 KB |
testcase_21 | AC | 2 ms
7,644 KB |
testcase_22 | AC | 3 ms
7,524 KB |
testcase_23 | AC | 3 ms
7,516 KB |
testcase_24 | AC | 2 ms
7,520 KB |
testcase_25 | AC | 2 ms
7,648 KB |
testcase_26 | AC | 3 ms
7,520 KB |
testcase_27 | AC | 3 ms
7,644 KB |
testcase_28 | AC | 3 ms
7,520 KB |
testcase_29 | AC | 2 ms
7,520 KB |
testcase_30 | AC | 3 ms
7,648 KB |
testcase_31 | AC | 3 ms
7,648 KB |
testcase_32 | AC | 3 ms
7,520 KB |
testcase_33 | AC | 3 ms
7,524 KB |
testcase_34 | AC | 3 ms
7,520 KB |
testcase_35 | AC | 3 ms
7,524 KB |
testcase_36 | AC | 3 ms
7,528 KB |
testcase_37 | AC | 3 ms
7,528 KB |
testcase_38 | AC | 3 ms
7,520 KB |
testcase_39 | AC | 3 ms
7,652 KB |
testcase_40 | AC | 3 ms
7,528 KB |
testcase_41 | AC | 3 ms
7,520 KB |
testcase_42 | AC | 3 ms
7,652 KB |
testcase_43 | AC | 3 ms
7,652 KB |
testcase_44 | AC | 3 ms
7,528 KB |
testcase_45 | AC | 3 ms
7,648 KB |
testcase_46 | AC | 3 ms
7,520 KB |
testcase_47 | AC | 3 ms
7,524 KB |
testcase_48 | AC | 3 ms
7,524 KB |
testcase_49 | AC | 3 ms
7,652 KB |
testcase_50 | AC | 3 ms
7,524 KB |
testcase_51 | AC | 3 ms
7,528 KB |
testcase_52 | AC | 3 ms
7,528 KB |
testcase_53 | AC | 3 ms
7,524 KB |
testcase_54 | AC | 3 ms
7,528 KB |
testcase_55 | AC | 15 ms
9,740 KB |
testcase_56 | AC | 26 ms
8,180 KB |
testcase_57 | AC | 28 ms
10,456 KB |
testcase_58 | AC | 14 ms
8,644 KB |
testcase_59 | AC | 19 ms
8,912 KB |
testcase_60 | AC | 12 ms
8,288 KB |
testcase_61 | AC | 25 ms
10,144 KB |
testcase_62 | AC | 25 ms
10,236 KB |
testcase_63 | AC | 25 ms
10,168 KB |
testcase_64 | AC | 15 ms
8,676 KB |
testcase_65 | AC | 28 ms
10,104 KB |
testcase_66 | AC | 28 ms
10,408 KB |
testcase_67 | AC | 21 ms
9,840 KB |
testcase_68 | AC | 19 ms
9,404 KB |
testcase_69 | AC | 25 ms
10,168 KB |
testcase_70 | AC | 30 ms
9,840 KB |
testcase_71 | AC | 17 ms
8,808 KB |
testcase_72 | AC | 35 ms
10,348 KB |
testcase_73 | AC | 33 ms
10,340 KB |
testcase_74 | AC | 21 ms
9,160 KB |
testcase_75 | AC | 32 ms
10,280 KB |
testcase_76 | AC | 23 ms
9,564 KB |
testcase_77 | AC | 17 ms
8,544 KB |
testcase_78 | AC | 17 ms
9,336 KB |
testcase_79 | AC | 16 ms
8,416 KB |
testcase_80 | AC | 33 ms
10,148 KB |
testcase_81 | AC | 33 ms
10,156 KB |
testcase_82 | AC | 25 ms
9,580 KB |
testcase_83 | AC | 26 ms
9,828 KB |
testcase_84 | AC | 23 ms
9,868 KB |
testcase_85 | AC | 5 ms
7,648 KB |
testcase_86 | AC | 22 ms
9,216 KB |
testcase_87 | AC | 29 ms
9,980 KB |
testcase_88 | AC | 13 ms
8,164 KB |
testcase_89 | AC | 27 ms
9,372 KB |
testcase_90 | AC | 13 ms
8,164 KB |
testcase_91 | AC | 29 ms
9,748 KB |
コンパイルメッセージ
main.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 59 | main() { | ^~~~
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);++i) #define rep2(i,a,b) for (int i=(a);i<(b);++i) #define rrep(i,n) for (int i=(n)-1;i>=0;--i) #define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i) #define chmin(a,b) (a)=min((a),(b)); #define chmax(a,b) (a)=max((a),(b)); #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define printV(_v) cout<<(#_v)<<":";for(auto(_x):(_v)){cout<<" "<<(_x);}cout<<endl; #define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;} #define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;} #define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl; #define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;} inline void output(){ cout << endl; } template<typename First, typename... Rest> inline void output(const First& first, const Rest&... rest) { cout << first << " "; output(rest...); } using ll = long long; using Pii = pair<int, int>; using TUPLE = tuple<int, int, int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; const int inf = 1ll << 60; const int mod = 1e9 + 7; using Graph = vector<vector<int>>; int N, A, B, W; int D[300010]; int deq[300010]; int dp[300010]; int a(int i) { return - i * B; } int b(int i) { return dp[i] + i * A + i * (i + 1) * B / 2; } int f(int i, int x) { return a(i) * x + b(i); } bool check(int f1, int f2, int f3) { int a1 = a(f1), b1 = b(f1); int a2 = a(f2), b2 = b(f2); int a3 = a(f3), b3 = b(f3); return (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a3 - a2); } main() { std::ios::sync_with_stdio(false); std::cin.tie(0); cin >> N >> A >> B >> W; rep(i, N) cin >> D[i]; int s = 0, t = 1; deq[0] = 0; dp[0] = W; rep2(i, 1, N + 1) { dp[i] = D[i - 1] - (i - 1) * A + i * (i - 1) * B / 2 + f(deq[s], i); while (s + 1 < t && check(deq[t - 2], deq[t - 1], i)) t--; deq[t++] = i; while (s + 1 < t && f(deq[s], i + 1) >= f(deq[s + 1], i + 1)) s++; } int ans = inf; rep(i, N + 1) { chmin(ans, dp[i] - (N - i) * A + (N - i) * (N - i + 1) * B / 2); } cout << ans << endl; }