結果

問題 No.703 ゴミ拾い Easy
ユーザー koprickykopricky
提出日時 2018-06-30 17:33:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,152 bytes
コンパイル時間 2,633 ms
コンパイル使用メモリ 173,012 KB
実行使用メモリ 10,376 KB
最終ジャッジ日時 2023-09-13 16:21:28
合計ジャッジ時間 5,319 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 22 ms
10,112 KB
testcase_37 WA -
testcase_38 AC 22 ms
10,108 KB
testcase_39 AC 22 ms
10,172 KB
testcase_40 AC 22 ms
10,148 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 25 ms
10,096 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
}

//f[j](x) = a[j]x + b[j]でaがjの増加に伴い単調減少する場合
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){
        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