結果

問題 No.703 ゴミ拾い Easy
ユーザー koprickykopricky
提出日時 2018-06-30 17:31:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 90 ms / 1,500 ms
コード長 1,887 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 150,216 KB
実行使用メモリ 10,284 KB
最終ジャッジ日時 2023-08-30 18:59:07
合計ジャッジ時間 5,782 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 87 ms
10,060 KB
testcase_25 AC 87 ms
10,120 KB
testcase_26 AC 88 ms
10,284 KB
testcase_27 AC 87 ms
10,128 KB
testcase_28 AC 87 ms
10,212 KB
testcase_29 AC 88 ms
10,120 KB
testcase_30 AC 88 ms
10,156 KB
testcase_31 AC 87 ms
10,080 KB
testcase_32 AC 88 ms
10,132 KB
testcase_33 AC 87 ms
10,132 KB
testcase_34 AC 76 ms
10,076 KB
testcase_35 AC 77 ms
10,016 KB
testcase_36 AC 76 ms
10,052 KB
testcase_37 AC 76 ms
10,052 KB
testcase_38 AC 77 ms
10,160 KB
testcase_39 AC 76 ms
10,048 KB
testcase_40 AC 77 ms
10,124 KB
testcase_41 AC 77 ms
10,132 KB
testcase_42 AC 76 ms
10,140 KB
testcase_43 AC 76 ms
10,024 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 90 ms
10,060 KB
testcase_47 AC 90 ms
10,016 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#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;

//f[j](x) = a[j]x + b[j]でaがjの増加に伴い単調減少する場合
template<typename T> 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 low = -1, high = lines.size() - 1;
		// while (high - low > 1) {
		// 	int mid = (high + low) / 2;
        //     if(f(mid, x) >= f(mid+1, x)){
        //         low = mid;
        //     }else{
        //         high = mid;
        //     }
		// }
		// return f(high, x);
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n),x(n),y(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> x[i];
    }
    rep(i,n){
        cin >> y[i];
    }
    CHT<ll> 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