結果

問題 No.703 ゴミ拾い Easy
ユーザー skyleeskylee
提出日時 2018-07-23 16:34:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 57 ms / 1,500 ms
コード長 1,919 bytes
コンパイル時間 1,248 ms
コンパイル使用メモリ 51,120 KB
実行使用メモリ 14,996 KB
最終ジャッジ日時 2023-08-30 18:59:42
合計ジャッジ時間 5,045 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,980 KB
testcase_01 AC 5 ms
11,084 KB
testcase_02 AC 5 ms
11,088 KB
testcase_03 AC 4 ms
11,088 KB
testcase_04 AC 4 ms
11,084 KB
testcase_05 AC 4 ms
11,120 KB
testcase_06 AC 4 ms
11,128 KB
testcase_07 AC 5 ms
11,092 KB
testcase_08 AC 4 ms
11,084 KB
testcase_09 AC 5 ms
11,132 KB
testcase_10 AC 5 ms
11,120 KB
testcase_11 AC 4 ms
11,088 KB
testcase_12 AC 4 ms
11,032 KB
testcase_13 AC 4 ms
11,144 KB
testcase_14 AC 4 ms
11,096 KB
testcase_15 AC 4 ms
11,108 KB
testcase_16 AC 4 ms
11,096 KB
testcase_17 AC 5 ms
11,128 KB
testcase_18 AC 5 ms
11,160 KB
testcase_19 AC 5 ms
11,044 KB
testcase_20 AC 5 ms
11,100 KB
testcase_21 AC 5 ms
11,132 KB
testcase_22 AC 5 ms
11,144 KB
testcase_23 AC 5 ms
11,096 KB
testcase_24 AC 55 ms
14,892 KB
testcase_25 AC 55 ms
14,996 KB
testcase_26 AC 55 ms
14,840 KB
testcase_27 AC 55 ms
14,892 KB
testcase_28 AC 55 ms
14,900 KB
testcase_29 AC 56 ms
14,932 KB
testcase_30 AC 56 ms
14,896 KB
testcase_31 AC 56 ms
14,900 KB
testcase_32 AC 56 ms
14,896 KB
testcase_33 AC 57 ms
14,976 KB
testcase_34 AC 49 ms
14,796 KB
testcase_35 AC 49 ms
14,924 KB
testcase_36 AC 47 ms
14,900 KB
testcase_37 AC 48 ms
14,840 KB
testcase_38 AC 47 ms
14,976 KB
testcase_39 AC 47 ms
14,896 KB
testcase_40 AC 49 ms
14,892 KB
testcase_41 AC 48 ms
14,892 KB
testcase_42 AC 49 ms
14,892 KB
testcase_43 AC 49 ms
14,936 KB
testcase_44 AC 5 ms
11,088 KB
testcase_45 AC 5 ms
11,120 KB
testcase_46 AC 53 ms
14,836 KB
testcase_47 AC 54 ms
14,788 KB
testcase_48 AC 5 ms
11,140 KB
testcase_49 AC 5 ms
11,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cctype>
#include<climits>
#include<algorithm>
inline int getint() {
	register char ch;
	while(!isdigit(ch=getchar()));
	register int x=ch^'0';
	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
	return x;
}
using int64=long long;
const int N=3e5+1,LIM=1e5;
int a[N],x[N],y[N];
int64 f[N];
using Line=std::pair<int64,int64>;
class SegmentTree {
	#define _left <<1
	#define _right <<1|1
	#define mid ((b+e)>>1)
	private:
		Line node[LIM<<2];
		int64 calc(const Line &l,const int &x) const {
			return l.first*x+l.second;
		}
	public:
		void build(const int &p,const int &b,const int &e) {
			node[p]={0,LLONG_MAX};
			if(b==e) return;
			build(p _left,b,mid);
			build(p _right,mid+1,e);
		}
		void insert(const int &p,const int &b,const int &e,Line l1) {
			if(node[p].second==LLONG_MAX) {
				node[p]=l1;
				return;
			}
			Line l2=node[p];
			if(calc(l2,b)>=calc(l1,b)) std::swap(l1,l2);
			if(calc(l1,e)>=calc(l2,e)) {
				node[p]=l2;
				return;
			}
			if(b==e) return;
			const double c=1.*(l2.second-l1.second)/(l1.first-l2.first);
			if(c<=mid) {
				node[p]=l1;
				insert(p _left,b,mid,l2);
			} else {
				node[p]=l2;
				insert(p _right,mid+1,e,l1);
			}
		}
		int64 query(const int &p,const int &b,const int &e,const int &x) const {
			int64 ret=calc(node[p],x);
			if(b==e) return ret;
			if(x<=mid) ret=std::min(ret,query(p _left,b,mid,x));
			if(x>mid) ret=std::min(ret,query(p _right,mid+1,e,x));
			return ret;
		}
	#undef _left
	#undef _right
	#undef mid
};
SegmentTree t;
int main() {
	const int n=getint();
	for(register int i=1;i<=n;i++) a[i]=getint();
	for(register int i=1;i<=n;i++) x[i]=getint();
	for(register int i=1;i<=n;i++) y[i]=getint();
	t.build(1,1,LIM);
	for(register int i=1;i<=n;i++) {
		t.insert(1,1,LIM,(Line){-2*x[i],(int64)x[i]*x[i]+(int64)y[i]*y[i]+f[i-1]});
		f[i]=t.query(1,1,LIM,a[i])+(int64)a[i]*a[i];
	}
	printf("%lld\n",f[n]);
	return 0;
}
0