結果

問題 No.703 ゴミ拾い Easy
ユーザー hashiryohashiryo
提出日時 2019-06-27 15:52:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 1,500 ms
コード長 1,680 bytes
コンパイル時間 3,596 ms
コンパイル使用メモリ 169,416 KB
実行使用メモリ 15,888 KB
最終ジャッジ日時 2023-08-30 19:08:34
合計ジャッジ時間 6,284 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,388 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 87 ms
10,392 KB
testcase_25 AC 87 ms
10,456 KB
testcase_26 AC 86 ms
10,436 KB
testcase_27 AC 87 ms
10,456 KB
testcase_28 AC 88 ms
10,524 KB
testcase_29 AC 87 ms
10,456 KB
testcase_30 AC 88 ms
10,596 KB
testcase_31 AC 88 ms
10,424 KB
testcase_32 AC 87 ms
10,560 KB
testcase_33 AC 87 ms
10,428 KB
testcase_34 AC 82 ms
15,292 KB
testcase_35 AC 81 ms
14,352 KB
testcase_36 AC 81 ms
14,148 KB
testcase_37 AC 80 ms
14,500 KB
testcase_38 AC 82 ms
15,888 KB
testcase_39 AC 81 ms
14,592 KB
testcase_40 AC 82 ms
14,464 KB
testcase_41 AC 81 ms
15,748 KB
testcase_42 AC 81 ms
14,776 KB
testcase_43 AC 81 ms
14,408 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 90 ms
10,444 KB
testcase_47 AC 90 ms
10,384 KB
testcase_48 AC 2 ms
4,384 KB
testcase_49 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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] << endl
using 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;
}
0