結果

問題 No.703 ゴミ拾い Easy
ユーザー koprickykopricky
提出日時 2018-06-30 17:34:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 1,500 ms
コード長 1,733 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 173,416 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2023-08-30 18:59:01
合計ジャッジ時間 4,526 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 22 ms
10,204 KB
testcase_25 AC 22 ms
10,052 KB
testcase_26 AC 23 ms
10,128 KB
testcase_27 AC 22 ms
10,140 KB
testcase_28 AC 22 ms
9,960 KB
testcase_29 AC 22 ms
10,172 KB
testcase_30 AC 21 ms
10,024 KB
testcase_31 AC 23 ms
10,140 KB
testcase_32 AC 22 ms
10,192 KB
testcase_33 AC 23 ms
10,240 KB
testcase_34 AC 20 ms
10,140 KB
testcase_35 AC 20 ms
9,956 KB
testcase_36 AC 20 ms
10,028 KB
testcase_37 AC 20 ms
10,200 KB
testcase_38 AC 19 ms
10,084 KB
testcase_39 AC 21 ms
10,136 KB
testcase_40 AC 21 ms
10,064 KB
testcase_41 AC 21 ms
10,088 KB
testcase_42 AC 20 ms
10,028 KB
testcase_43 AC 21 ms
10,032 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 21 ms
10,048 KB
testcase_47 AC 24 ms
10,188 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define ll long long
#define fi first
#define se second
#define push_back pb
#define show(x) cout << #x << " = " << x << "\n"

using namespace std;

typedef pair<int,int> P;

#define T long long

#define getchar getchar_unlocked

inline int in() {
    int n, c;
    while ((c = getchar()) < '0') if (c == EOF) return -1;
    n = c - '0';
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

class CHT
{
private:
    using ptt = pair<T, T>;
    bool check(ptt l1, ptt l2, ptt l3){
        return (l2.first-l1.first)*(l3.second-l2.second)>=(l2.second-l1.second)*(l3.first-l2.first);
    }
    T f(int i, T x){
        return lines[i].first * x + lines[i].second;
    }
public:
    vector<ptt> lines;
    CHT(){};
    void add(T a, T b){
        ptt line(a, b);
        while((int)lines.size() >= 2 && check(*(lines.end()-2), lines.back(), line)){
            lines.pop_back();
        }
        lines.emplace_back(line);
    }
    T get(T x){
        static int head = 0;
        while((int)lines.size() - head >= 2 && f(head, x) > f(head + 1, x)){
            head++;
        }
        return f(head, x);
    }
};

int main()
{
    int n = in();
    vector<ll> a(n),x(n),y(n);
    rep(i,n){
        a[i] = in();
    }
    rep(i,n){
        x[i] = in();
    }
    rep(i,n){
        y[i] = in();
    }
    CHT cht;
    cht.add(-2*x[0],x[0]*x[0]+y[0]*y[0]);
    rep(i,n){
        if(i < n-1){
            cht.add(-2*x[i+1],cht.get(a[i])+x[i+1]*x[i+1]+y[i+1]*y[i+1]+a[i]*a[i]);
        }else{
            cout << cht.get(a[i])+a[i]*a[i] << "\n";
            return 0;
        }
    }
}
;
0