結果

問題 No.703 ゴミ拾い Easy
ユーザー 👑 kmjpkmjp
提出日時 2018-09-08 22:27:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,607 bytes
コンパイル時間 2,523 ms
コンパイル使用メモリ 166,128 KB
実行使用メモリ 13,192 KB
最終ジャッジ日時 2023-08-23 07:07:01
合計ジャッジ時間 8,969 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,000 KB
testcase_01 AC 2 ms
5,012 KB
testcase_02 AC 2 ms
4,944 KB
testcase_03 AC 2 ms
5,008 KB
testcase_04 AC 2 ms
5,004 KB
testcase_05 AC 2 ms
5,064 KB
testcase_06 AC 2 ms
4,944 KB
testcase_07 AC 2 ms
5,008 KB
testcase_08 AC 2 ms
5,008 KB
testcase_09 AC 2 ms
4,948 KB
testcase_10 AC 1 ms
5,196 KB
testcase_11 AC 2 ms
5,012 KB
testcase_12 AC 2 ms
4,940 KB
testcase_13 AC 2 ms
5,132 KB
testcase_14 AC 3 ms
5,008 KB
testcase_15 AC 3 ms
5,008 KB
testcase_16 AC 3 ms
5,008 KB
testcase_17 AC 3 ms
5,004 KB
testcase_18 AC 3 ms
5,008 KB
testcase_19 AC 3 ms
4,944 KB
testcase_20 AC 3 ms
5,008 KB
testcase_21 AC 3 ms
5,008 KB
testcase_22 AC 3 ms
5,004 KB
testcase_23 AC 3 ms
5,068 KB
testcase_24 AC 214 ms
12,936 KB
testcase_25 AC 216 ms
12,952 KB
testcase_26 AC 214 ms
12,928 KB
testcase_27 AC 214 ms
12,924 KB
testcase_28 AC 218 ms
13,112 KB
testcase_29 AC 216 ms
12,868 KB
testcase_30 AC 216 ms
12,876 KB
testcase_31 AC 215 ms
13,192 KB
testcase_32 AC 215 ms
12,864 KB
testcase_33 AC 214 ms
13,072 KB
testcase_34 AC 80 ms
12,984 KB
testcase_35 AC 79 ms
12,764 KB
testcase_36 AC 79 ms
12,840 KB
testcase_37 AC 79 ms
12,916 KB
testcase_38 AC 79 ms
12,768 KB
testcase_39 AC 79 ms
12,832 KB
testcase_40 AC 79 ms
12,832 KB
testcase_41 AC 79 ms
12,844 KB
testcase_42 AC 79 ms
12,856 KB
testcase_43 AC 81 ms
13,052 KB
testcase_44 AC 2 ms
5,008 KB
testcase_45 AC 2 ms
5,008 KB
testcase_46 AC 94 ms
12,900 KB
testcase_47 AC 92 ms
12,896 KB
testcase_48 WA -
testcase_49 AC 3 ms
4,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<typename V> struct ConvexHullOnline {
	const V inf=1LL<<60+1;
	const int cmptype=1; // 0-max 1-min
	map<V,V> Q,PR; // Q[a]=b -> a*x+b, P[a]=c ax+b is best unti x<=c PR[c]=a
	unordered_map<V,V> P;
	ConvexHullOnline() { Q[inf]=-inf*inf; Q[-inf]=inf*inf;}
	int ok(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or min
		if(A.first==-inf && C.first==inf) return 1;
		return ((__int128_t)(B.second-A.second)*(B.first-C.first)<=(__int128)(C.second-B.second)*(A.first-B.first));
	}
	bool bad(typename map<V,V>::iterator it) {
		if(it==Q.begin() || next(it)==Q.end() || next(it)->first==inf || prev(it)->first==-inf) return false;
		return ok(*prev(it),*it,*next(it))==0;
	}
	void erase(typename map<V,V>::iterator it) { PR.erase(P[it->first]); P.erase(it->first); Q.erase(it);}
	void update(typename map<V,V>::iterator it) {
		if(next(it)==Q.end() || it==Q.begin()) return;
		auto it2=next(it);
		if(it2->first==inf) {
			P[it->first]=inf; PR[inf]=it->first;
		}
		else {
			P[it->first]=(it2->second-it->second)/(it->first-it2->first);
			PR[P[it->first]]=it->first;
		}
	}
	
	void add(V a, V b) { // add ax+b
		if(cmptype) a=-a, b=-b;
		if(Q.count(a)) if(Q[a]==b || Q[a]>b) return;
		Q[a]=b;
		auto it=Q.find(a);
		if(bad(it)) return (void)Q.erase(it);
		while(bad(next(it))) erase(next(it));
		while(bad(prev(it))) erase(prev(it));
		PR.erase(P[it->first]); P.erase(it->first);
		if(prev(it)!=Q.begin()) PR.erase(P[prev(it)->first]); P.erase(prev(it)->first);
		update(it);update(prev(it));
	}
	V query(V x) {
		auto it=PR.lower_bound(x);
		return (it->second*x+Q[it->second])*(cmptype?-1:1);
	}
};

int N;
ll A[303030];
ll X[303030];
ll Y[303030];
ll D[303030];
ConvexHullOnline<ll> cht;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	FOR(i,N) cin>>X[i];
	FOR(i,N) cin>>Y[i];
	
	FOR(i,N) {
		cht.add(-2*X[i],D[i]+X[i]*X[i]+Y[i]*Y[i]);
		D[i+1]=cht.query(A[i])+A[i]*A[i];
	}
	cout<<D[N]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0