結果
問題 | No.703 ゴミ拾い Easy |
ユーザー |
![]() |
提出日時 | 2019-06-27 15:52:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 89 ms / 1,500 ms |
コード長 | 1,680 bytes |
コンパイル時間 | 1,738 ms |
コンパイル使用メモリ | 166,908 KB |
実行使用メモリ | 16,092 KB |
最終ジャッジ日時 | 2025-01-02 14:15:23 |
合計ジャッジ時間 | 5,577 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 46 |
ソースコード
#include<bits/stdc++.h>#define debug(x) cerr << #x << ": " << x << endl#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endlusing namespace std;typedef long long ll;typedef unsigned long long ull;typedef vector<ll> vll;const ll INF = LLONG_MAX/2;const ll MOD = 1e9+7;const double EPS=1e-12;template<typename T>class ConvexHullTrick {private:vector<pair<T, T>> lines;int head;bool check(pair<T, T> l1, pair<T, T> l2, pair<T, T> l3) {return (l3.second - l2.second) * (l2.first - l1.first) >= (l2.second - l1.second) * (l3.first - l2.first);}T f(int i, T x) {return lines[i].first * x + lines[i].second;}public:ConvexHullTrick():head(0){}bool empty(){return lines.size()-head==0;}void insert(T a, T b) {pair<T, T> line(a, b);if(lines.size()-head>=1&&a==lines.back().first&&b>lines.back().second)return;while (lines.size()-head >= 2 && check(*(lines.end() - 2), lines.back(), line))lines.pop_back();lines.emplace_back(line);}T getmin(T x) {while (lines.size() - head >= 2 && (f(head, x)>=f(head + 1, x)))++head;return f(head, x);}};signed main(){cin.tie(0);ios::sync_with_stdio(false);ll N;cin>>N;ll a[N];for(ll i=0;i<N;i++)cin>>a[i];ll x[N];for(ll i=0;i<N;i++)cin>>x[i];ll y[N];for(ll i=0;i<N;i++)cin>>y[i];ConvexHullTrick<ll> cht;ll dp=0;for(ll i=0;i<N;i++){cht.insert(-2*x[i],x[i]*x[i]+y[i]*y[i]+dp);dp=cht.getmin(a[i])+a[i]*a[i];}cout<<dp<<endl;return 0;}