提出 #12286413
ソースコード 拡げる
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define int ll
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<long long, long long> pll; typedef cc_hash_table<int, int, hash<int>> intHashTable;
struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
inline int powMod(int a, int b) { int x = 1; while (b > 0) { if (b&1) x = (x*a) % MOD; a = (a*a) % MOD; b >>= 1; } return x; }
inline int multiply(int x, int y) { return ((x % MOD) * (y % MOD)) % MOD; }
inline int divide(int x, int y) { return ((x % MOD) * powMod(y % MOD, MOD-2)) % MOD; }
inline int ceil(int a, int b) { return (a+b-1)/b; }
int gcd (int a, int b) { while (b) { a %= b; swap(a, b); } return a; }
int lcm (int a, int b) { return a / gcd(a, b) * b; }
int inverseMod(int a, int m) { a = a % m; for (ll x = 1; x < m; x++) if ((a * x) % m == 1) return x; return -1; }
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
int str_replace(string& str, const string& from, const string& to, int limit = -1) { if(from.empty()) return 0; size_t start_pos = 0; int cnt = 0; while((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); cnt++; if (cnt == limit) break; } return cnt; }
template<int D, typename T> struct vec : public vector<vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) { } }; template<typename T> struct vec<1, T> : public vector<T> { vec(int n = 0, T val = T()) : vector<T>(n, val) { }};
const int MAXN = 2e7;
typedef pii point;
point line[4*MAXN];
int dot(point a, point b) { return (a.F*b.F + a.S*b.S); }
int f(point a, int x) { return dot(a, {x, 1}); }
void addLine(point pt, int v = 1, int l = 0, int r = MAXN)
{
int m = (l+r) / 2;
bool lef = (f(pt, l) < f(line[v], l)), mid = (f(pt, m) < f(line[v], m));
if (mid) swap(line[v], pt);
if (r-l == 1) return;
else if (lef != mid) addLine(pt, 2*v, l, m);
else addLine(pt, 2*v + 1, m, r);
}
int get(int x, int v = 1, int l = 0, int r = MAXN)
{
int m = (l+r) / 2;
if (r-l == 1) return f(line[v], x);
else if (x < m) return min(f(line[v], x), get(x, 2*v, l, m));
else return min(f(line[v], x), get(x, 2*v + 1, m, r));
}
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, c; cin >> n >> c;
vec<1, int> h(n);
for (auto &x : h) cin >> x;
for (int i = 0; i < n; ++i)
{
int dp = (i == 0) ? 0 : get(h[i]) + h[i]*h[i] + c;
addLine({-2*h[i], dp + h[i]*h[i]});
if (i == n-1) cout << dp << '\n';
}
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
Z - Frog 3 |
| ユーザ |
ankit_priyarup |
| 言語 |
C++14 (GCC 5.4.1) |
| 得点 |
100 |
| コード長 |
3945 Byte |
| 結果 |
AC |
| 実行時間 |
164 ms |
| メモリ |
114688 KiB |
ジャッジ結果
| セット名 |
All |
| 得点 / 配点 |
100 / 100 |
| 結果 |
|
| セット名 |
テストケース |
| All |
0_00, 0_01, 0_02, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18, 1_19, 1_20, 1_21, 1_22, 1_23, 1_24, 1_25, 1_26, 1_27, 1_28, 1_29, 1_30, 1_31, 1_32, 1_33, 1_34, 1_35 |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 0_00 |
AC |
1 ms |
256 KiB |
| 0_01 |
AC |
1 ms |
256 KiB |
| 0_02 |
AC |
1 ms |
256 KiB |
| 1_00 |
AC |
1 ms |
256 KiB |
| 1_01 |
AC |
1 ms |
256 KiB |
| 1_02 |
AC |
136 ms |
12160 KiB |
| 1_03 |
AC |
137 ms |
18304 KiB |
| 1_04 |
AC |
137 ms |
22400 KiB |
| 1_05 |
AC |
156 ms |
98304 KiB |
| 1_06 |
AC |
164 ms |
81920 KiB |
| 1_07 |
AC |
137 ms |
30592 KiB |
| 1_08 |
AC |
137 ms |
38784 KiB |
| 1_09 |
AC |
138 ms |
51072 KiB |
| 1_10 |
AC |
137 ms |
46976 KiB |
| 1_11 |
AC |
139 ms |
55168 KiB |
| 1_12 |
AC |
134 ms |
49024 KiB |
| 1_13 |
AC |
143 ms |
67456 KiB |
| 1_14 |
AC |
144 ms |
69504 KiB |
| 1_15 |
AC |
145 ms |
75648 KiB |
| 1_16 |
AC |
154 ms |
114688 KiB |
| 1_17 |
AC |
155 ms |
104448 KiB |
| 1_18 |
AC |
152 ms |
86016 KiB |
| 1_19 |
AC |
149 ms |
75648 KiB |
| 1_20 |
AC |
153 ms |
100352 KiB |
| 1_21 |
AC |
151 ms |
81920 KiB |
| 1_22 |
AC |
153 ms |
100352 KiB |
| 1_23 |
AC |
148 ms |
69504 KiB |
| 1_24 |
AC |
153 ms |
86016 KiB |
| 1_25 |
AC |
153 ms |
98304 KiB |
| 1_26 |
AC |
149 ms |
102272 KiB |
| 1_27 |
AC |
154 ms |
104448 KiB |
| 1_28 |
AC |
152 ms |
100352 KiB |
| 1_29 |
AC |
155 ms |
110592 KiB |
| 1_30 |
AC |
144 ms |
77696 KiB |
| 1_31 |
AC |
147 ms |
77696 KiB |
| 1_32 |
AC |
150 ms |
65408 KiB |
| 1_33 |
AC |
152 ms |
100352 KiB |
| 1_34 |
AC |
149 ms |
96128 KiB |
| 1_35 |
AC |
154 ms |
106496 KiB |