結果
| 問題 |
No.409 ダイエット
|
| コンテスト | |
| ユーザー |
akusyounin2412
|
| 提出日時 | 2019-02-03 22:32:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,259 bytes |
| コンパイル時間 | 1,593 ms |
| コンパイル使用メモリ | 132,952 KB |
| 実行使用メモリ | 10,600 KB |
| 最終ジャッジ日時 | 2024-12-21 16:38:12 |
| 合計ジャッジ時間 | 8,691 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 85 RE * 1 |
ソースコード
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[220000],a[200020], b[220000];
string str, ss;
bool f[220000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge {
LL from, to, cost;
};
vector<vector<Edge>>vec,rvec;
vector<edge>ed;
vector<LL>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
if (f)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void yn(bool f) {
if (f)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template<typename T>
class ConvecHullTrick {
private:
// 直線群(配列)
std::vector<std::pair<T, T>> lines;
// 最小値(最大値)を求めるxが単調であるか
bool isMonotonicX;
// 最小/最大を判断する関数
std::function<bool(T l, T r)> comp;
public:
// コンストラクタ ( クエリが単調であった場合はflag = trueとする )
ConvecHullTrick(bool flagX = false, std::function<bool(T l, T r)> compFunc = [](T l, T r) {return l >= r; })
:isMonotonicX(flagX), comp(compFunc) {
lines.emplace_back(0, 0);
};
// 直線l1, l2, l3のうちl2が不必要であるかどうか
bool check(std::pair<T, T> l1, std::pair<T, T> l2, std::pair<T, T> l3) {
if (l1 < l3) std::swap(l1, l3);
return (l3.second - l2.second) * (l2.first - l1.first) >= (l2.second - l1.second) * (l3.first - l2.first);
}
// 直線y=ax+bを追加する
void add(T a, T b) {
std::pair<T, T> line(a, b);
while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line))
lines.pop_back();
lines.emplace_back(line);
}
// i番目の直線f_i(x)に対するxの時の値を返す
T f(int i, T x) {
return lines[i].first * x + lines[i].second;
}
// i番目の直線f_i(x)に対するxの時の値を返す
T f(std::pair<T, T> line, T x) {
return line.first * x + line.second;
}
// 直線群の中でxの時に最小(最大)となる値を返す
T get(T x) {
// 最小値(最大値)クエリにおけるxが単調
if (isMonotonicX) {
static int head = 0;
while (lines.size() - head >= 2 && comp(f(head, x), f(head + 1, x)))
++head;
return f(head, x);
}
else {
int low = -1, high = lines.size() - 1;
while (high - low > 1) {
int mid = (high + low) / 2;
(comp(f(mid, x), f(mid + 1, x)) ? low : high) = mid;
}
return f(high, x);
}
}
};
int main() {
ConvecHullTrick<LL> cht(false);
LL A, B;
cin >> n >> A >> B >> s;
rep(i, n) {
cin >> a[i];
}
dp[0] = a[0] * 2;
cht.add(0, dp[0] * 2 + a[0] * 2);
for(int i=1;i<n;i++) {
dp[i] = a[i]*2 - A * (i-1)*2 + (i*i - i)*B + cht.get(i);
cht.add(-B * i*2, dp[i]*2 + a[i]*2 + (i*i + i)*B);
}
ans = -A * n + B * (n)*(n + 1) / 2;
rep(i, n) {
dp[i] /= 2;
ans = min(ans, dp[i] - (n - i - 1)*A + B * (n - i - 1)*(n - i) / 2);
}
cout << ans + s << endl;
return 0;
}
akusyounin2412