結果

問題 No.2012 Largest Triangle
ユーザー 👑 kmjpkmjp
提出日時 2022-09-27 22:55:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,761 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 218,048 KB
実行使用メモリ 8,424 KB
最終ジャッジ日時 2023-08-24 04:11:09
合計ジャッジ時間 10,189 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 133 ms
6,604 KB
testcase_17 AC 132 ms
6,540 KB
testcase_18 AC 131 ms
6,580 KB
testcase_19 AC 132 ms
6,536 KB
testcase_20 AC 130 ms
6,540 KB
testcase_21 AC 130 ms
6,580 KB
testcase_22 AC 132 ms
6,560 KB
testcase_23 WA -
testcase_24 AC 131 ms
6,612 KB
testcase_25 AC 132 ms
6,680 KB
testcase_26 AC 392 ms
7,948 KB
testcase_27 AC 382 ms
7,748 KB
testcase_28 AC 388 ms
7,816 KB
testcase_29 AC 388 ms
7,920 KB
testcase_30 AC 395 ms
7,824 KB
testcase_31 AC 194 ms
6,600 KB
testcase_32 AC 198 ms
6,700 KB
testcase_33 AC 195 ms
6,660 KB
testcase_34 AC 195 ms
6,692 KB
testcase_35 AC 200 ms
6,684 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 104 ms
8,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#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 FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
double X[202020],Y[202020];

template<typename V> struct ConvexHullOnline {
	const V inf=1LL<<40+1;
	const int cmptype=0; // 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]=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 ((B.second-A.second)*(B.first-C.first)<=(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);
	}
};
ConvexHullOnline<double> cho;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	double ma=0;
	double my=0;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		cho.add(-Y[i],X[i]);
		cho.add(Y[i],-X[i]);
		my=max(my,abs(Y[i]));
		if(Y[i]==0) {
			ma=abs(X[i]*my);
		}
		else {
			ma=max(ma,abs(Y[i]*cho.query(X[i]/Y[i])));
		}
	}
	cout<<(ll)(round(ma))<<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