結果

問題 No.703 ゴミ拾い Easy
ユーザー koprickykopricky
提出日時 2018-06-30 18:07:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 1,500 ms
コード長 1,576 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 167,860 KB
実行使用メモリ 9,732 KB
最終ジャッジ日時 2023-08-30 18:59:12
合計ジャッジ時間 4,605 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,620 KB
testcase_01 AC 2 ms
5,508 KB
testcase_02 AC 2 ms
5,408 KB
testcase_03 AC 2 ms
5,440 KB
testcase_04 AC 2 ms
5,440 KB
testcase_05 AC 2 ms
5,444 KB
testcase_06 AC 2 ms
5,436 KB
testcase_07 AC 2 ms
5,420 KB
testcase_08 AC 2 ms
5,448 KB
testcase_09 AC 2 ms
5,420 KB
testcase_10 AC 2 ms
5,364 KB
testcase_11 AC 2 ms
5,400 KB
testcase_12 AC 2 ms
5,396 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,380 KB
testcase_15 AC 2 ms
5,652 KB
testcase_16 AC 2 ms
5,392 KB
testcase_17 AC 3 ms
5,472 KB
testcase_18 AC 3 ms
5,412 KB
testcase_19 AC 2 ms
5,460 KB
testcase_20 AC 2 ms
5,528 KB
testcase_21 AC 2 ms
5,464 KB
testcase_22 AC 2 ms
5,372 KB
testcase_23 AC 2 ms
5,572 KB
testcase_24 AC 20 ms
7,396 KB
testcase_25 AC 19 ms
7,484 KB
testcase_26 AC 20 ms
7,668 KB
testcase_27 AC 20 ms
7,472 KB
testcase_28 AC 20 ms
7,472 KB
testcase_29 AC 20 ms
7,480 KB
testcase_30 AC 19 ms
7,488 KB
testcase_31 AC 20 ms
7,484 KB
testcase_32 AC 20 ms
7,392 KB
testcase_33 AC 19 ms
7,480 KB
testcase_34 AC 18 ms
9,444 KB
testcase_35 AC 18 ms
9,712 KB
testcase_36 AC 19 ms
9,584 KB
testcase_37 AC 18 ms
9,456 KB
testcase_38 AC 18 ms
9,732 KB
testcase_39 AC 18 ms
9,536 KB
testcase_40 AC 18 ms
9,464 KB
testcase_41 AC 18 ms
9,440 KB
testcase_42 AC 18 ms
9,504 KB
testcase_43 AC 18 ms
9,456 KB
testcase_44 AC 2 ms
5,372 KB
testcase_45 AC 2 ms
5,564 KB
testcase_46 AC 19 ms
7,512 KB
testcase_47 AC 21 ms
7,424 KB
testcase_48 AC 3 ms
5,464 KB
testcase_49 AC 2 ms
5,444 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;

const int MAX_N = 300001;

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

pair<ll,ll> lines[MAX_N];

bool check(pair<ll,ll> l1, pair<ll,ll> l2, pair<ll,ll> l3){
    return (l2.first-l1.first)*(l3.second-l2.second)>=(l2.second-l1.second)*(l3.first-l2.first);
}

ll f(int i, ll x){
    return lines[i].first * x + lines[i].second;
}

int head = 0, tail = 0;

void add(ll a, ll b){
	pair<ll,ll> line(a, b);
	while(tail - head >= 2 && check(lines[tail-2], lines[tail-1], line)){
		tail--;
	}
	lines[tail++] = line;
}

ll get(ll x){
    while(tail - head >= 2 && f(head, x) >= f(head + 1, x)){
        head++;
    }
    return f(head, x);
}

int a[MAX_N],x[MAX_N],y[MAX_N];

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