結果

問題 No.703 ゴミ拾い Easy
ユーザー leaf_1415leaf_1415
提出日時 2019-09-25 20:23:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 99 ms / 1,500 ms
コード長 1,913 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 66,168 KB
実行使用メモリ 16,552 KB
最終ジャッジ日時 2023-08-30 19:11:29
合計ジャッジ時間 5,246 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,076 KB
testcase_01 AC 5 ms
13,108 KB
testcase_02 AC 4 ms
13,228 KB
testcase_03 AC 4 ms
13,124 KB
testcase_04 AC 5 ms
13,076 KB
testcase_05 AC 5 ms
13,184 KB
testcase_06 AC 5 ms
13,080 KB
testcase_07 AC 5 ms
13,184 KB
testcase_08 AC 5 ms
13,224 KB
testcase_09 AC 5 ms
13,120 KB
testcase_10 AC 5 ms
13,112 KB
testcase_11 AC 5 ms
13,232 KB
testcase_12 AC 5 ms
13,120 KB
testcase_13 AC 5 ms
13,228 KB
testcase_14 AC 5 ms
13,188 KB
testcase_15 AC 6 ms
13,300 KB
testcase_16 AC 6 ms
13,308 KB
testcase_17 AC 6 ms
13,220 KB
testcase_18 AC 5 ms
13,164 KB
testcase_19 AC 5 ms
13,080 KB
testcase_20 AC 6 ms
13,304 KB
testcase_21 AC 6 ms
13,284 KB
testcase_22 AC 5 ms
13,204 KB
testcase_23 AC 5 ms
13,184 KB
testcase_24 AC 96 ms
16,552 KB
testcase_25 AC 95 ms
16,460 KB
testcase_26 AC 96 ms
16,436 KB
testcase_27 AC 95 ms
16,440 KB
testcase_28 AC 95 ms
16,412 KB
testcase_29 AC 95 ms
16,440 KB
testcase_30 AC 95 ms
16,440 KB
testcase_31 AC 95 ms
16,444 KB
testcase_32 AC 95 ms
16,412 KB
testcase_33 AC 95 ms
16,440 KB
testcase_34 AC 84 ms
16,436 KB
testcase_35 AC 85 ms
16,392 KB
testcase_36 AC 83 ms
16,460 KB
testcase_37 AC 85 ms
16,452 KB
testcase_38 AC 82 ms
16,496 KB
testcase_39 AC 83 ms
16,412 KB
testcase_40 AC 86 ms
16,436 KB
testcase_41 AC 85 ms
16,412 KB
testcase_42 AC 86 ms
16,440 KB
testcase_43 AC 85 ms
16,504 KB
testcase_44 AC 6 ms
13,344 KB
testcase_45 AC 5 ms
13,112 KB
testcase_46 AC 99 ms
16,396 KB
testcase_47 AC 97 ms
16,476 KB
testcase_48 AC 6 ms
13,228 KB
testcase_49 AC 5 ms
13,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

struct LiChaoTree{
	int size;
	vector<P> seg;
	
	LiChaoTree(){}
	LiChaoTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = make_pair(0, inf);
	}
	llint calc(P f, llint x)
	{
		return f.first * x + f.second;
	}
	llint query(int x) //xにおける最小値を取得
	{
		int i = x + (1 << size);
		llint ret = inf;
		while(i >= 1){
			ret = min(ret, calc(seg[i], x));
			i /= 2;
		}
		return ret;
	}
	void add(int k, int l, int r, P f)
	{
		int m = (l+r)/2;
		if(calc(f, m) < calc(seg[k], m)) swap(seg[k], f);
		bool L = (calc(f, l) < calc(seg[k], l)), R = (calc(f, r) < calc(seg[k], r));
		if(L == R) return;
		if(L) add(k*2, l, m, f);
		if(R) add(k*2+1, m+1, r, f);
	}
	void addSegment(int a, int b, int k, int l, int r, P f)
	{
		if(b < l || r < a) return;
		if(a <= l && r <= b){
			add(k, l, r, f);
			return;
		}
		addSegment(a, b, k*2, l, (l+r)/2, f);
		addSegment(a, b, k*2+1, (l+r)/2+1, r, f);
	}
	void addSegment(int a, int b, llint p, llint q) //区間[a, b]に線分px+qを追加
	{
		addSegment(a, b, 1, 0, (1<<size)-1, make_pair(p, q));
	}
	void addLine(llint p, llint q) //直線px+qを追加
	{
		return addSegment(0, (1<<size)-1, p, q);
	}
};

llint n;
llint a[300005], x[300005], y[300005];
llint dp[300005];
LiChaoTree lct(17);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = n; i >= 1; i--) cin >> a[i];
	for(int i = n; i >= 1; i--) cin >> x[i];
	for(int i = n; i >= 1; i--) cin >> y[i];
	
	lct.init();
	dp[0] = 0;
	lct.addLine(-2*a[1], a[1]*a[1]+dp[0]);
	
	for(int i = 1; i <= n; i++){
		dp[i] = lct.query(x[i]) + x[i]*x[i] + y[i]*y[i];
		lct.addLine(-2*a[i+1], a[i+1]*a[i+1]+dp[i]);
	}
	cout << dp[n] << endl;
	
	return 0;
}
0