結果

問題 No.703 ゴミ拾い Easy
ユーザー koprickykopricky
提出日時 2018-06-30 17:06:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,683 bytes
コンパイル時間 1,860 ms
コンパイル使用メモリ 150,464 KB
実行使用メモリ 10,400 KB
最終ジャッジ日時 2023-09-13 16:21:19
合計ジャッジ時間 6,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 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,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 87 ms
10,168 KB
testcase_25 AC 87 ms
10,064 KB
testcase_26 AC 88 ms
10,112 KB
testcase_27 AC 87 ms
10,184 KB
testcase_28 AC 87 ms
10,168 KB
testcase_29 AC 87 ms
10,116 KB
testcase_30 AC 88 ms
10,232 KB
testcase_31 AC 88 ms
10,400 KB
testcase_32 AC 87 ms
10,244 KB
testcase_33 AC 87 ms
10,040 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,384 KB
testcase_46 AC 92 ms
10,236 KB
testcase_47 AC 90 ms
10,316 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 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"
#define int long long

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

signed 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];
        a[i]++;
    }
    rep(i,n){
        cin >> x[i];
        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){
            auto res = cht.get(a[i]);
            cht.add(-2*x[i+1],res+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