結果
問題 | No.703 ゴミ拾い Easy |
ユーザー | vwxyz |
提出日時 | 2024-12-04 15:53:30 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,168 bytes |
コンパイル時間 | 3,760 ms |
コンパイル使用メモリ | 282,816 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-12-04 15:53:50 |
合計ジャッジ時間 | 18,787 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | AC | 2 ms
5,248 KB |
testcase_45 | AC | 2 ms
5,248 KB |
testcase_46 | AC | 270 ms
10,240 KB |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | RE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); } #define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,N) for(int i=0;i<(int)(N);i++) #define rep1(i,N) for(int i=1;i<=(int)(N);i++) #define fs first #define sc second #define eb emplace_back #define pb eb #define all(x) x.begin(),x.end() template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } // bit op int popcnt(uint x) { return __builtin_popcount(x); } int popcnt(ull x) { return __builtin_popcountll(x); } int bsr(uint x) { return 31 - __builtin_clz(x); } int bsr(ull x) { return 63 - __builtin_clzll(x); } int bsf(uint x) { return __builtin_ctz(x); } int bsf(ull x) { return __builtin_ctzll(x); } template<class T> struct ConvexHull { using L = array<T, 2>; bool que_incr; ConvexHull(bool _que_incr) : que_incr(_que_incr) {} deque<L> lines; // can remove mid? static bool is_need(L mid, L left, L right) { assert(left[0] <= mid[0] && mid[0] <= right[0]); return (right[0]-mid[0])*(left[1]-mid[1]) < (mid[0]-left[0])*(mid[1]-right[1]); } //work with 2^(60 + 64) /*static bool is_need(L mid, L left, L right) { assert(left[0] <= mid[0] && mid[0] <= right[0]); ll a = (right[0]-mid[0]), b = (left[1]-mid[1]), c = (mid[0]-left[0]), d = (mid[1]-right[1]); long double x = (long double)(a) * b - (long double)(c) * d; if (abs(x) > (1LL << 60)) return x < 0; int fl = b < 0, fr = d < 0; if (fl != fr) return fl == 1; ull z = ull(a) * ull(abs(b)) - ull(c) * ull(abs(d)); if (fl == 0) return (1ULL << 63) < z; return z < (1ULL << 63); }*/ void insert_front(L l) { if (lines.empty()) { lines.push_front(l); return; } assert(l[0] <= lines[0][0]); if (l[0] == lines[0][0]) { if (l[1] <= lines[0][1]) return; lines.pop_front(); } while (lines.size() >= 2 && !is_need(lines.front(), l, lines[1])) { lines.pop_front(); } lines.push_front(l); } void insert_back(L l) { if (lines.empty()) { lines.push_back(l); return; } assert(lines.back()[0] <= l[0]); if (lines.back()[0] == l[0]) { if (l[1] <= lines.back()[1]) return; lines.pop_back(); } while (lines.size() >= 2 && !is_need(lines.back(),lines[lines.size()-2], l)) { lines.pop_back(); } lines.push_back(l); } /** Insert line line's degree must be minimum or maximum */ void insert_line(L line) { if (lines.empty()) { lines.push_back(line); return; } if (line[0] <= lines[0][0]) insert_front(line); else if (lines.back()[0] <= line[0]) insert_back(line); else assert(false); //line's degree must be minimum or maximum } /// get maximum y T b_x; T first = true; T max_y(T x) { assert(lines.size()); auto value = [&](L l) { return l[0] * x + l[1]; }; if (que_incr) { assert(first || b_x <= x); first = false; b_x = x; while (lines.size() >= 2 &&value(lines[0]) <= value(lines[1])) { lines.pop_front(); } return value(lines.front()); } else { assert(first || x <= b_x); first = false; b_x = x; while (lines.size() >= 2 && value(lines[lines.size()-2]) >= value(lines.back())) { lines.pop_back(); } return value(lines.back()); } } }; int main(){ int N;cin>>N; vector<ll> A(N); vector<ll> X(N); vector<ll> Y(N); for(int i=0;i<N;i++){ cin>>A[i]; } for(int i=0;i<N;i++){ cin>>X[i]; } for(int i=0;i<N;i++){ cin>>Y[i]; } ConvexHull<ll> dp(false); ll cost=0; for(int i=0;i<N;i++){ dp.insert_line({2*X[i],-cost-X[i]*X[i]-Y[i]*Y[i]}); cost=-dp.max_y(A[i])+A[i]*A[i]; } ll ans=cost; cout<<ans<<"\n"; } // dp=Convex_Hull_Trick_deque() // cost=0 // for i in range(N): // dp.add_line(-2*X[i],cost+X[i]**2+Y[i]**2) // cost=dp(A[i])+A[i]**2 // ans=cost // print(ans)