結果

問題 No.2012 Largest Triangle
ユーザー 👑 kmjpkmjp
提出日時 2022-09-27 23:21:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,500 ms
コード長 2,226 bytes
コンパイル時間 2,314 ms
コンパイル使用メモリ 212,296 KB
実行使用メモリ 20,524 KB
最終ジャッジ日時 2023-08-24 04:11:55
合計ジャッジ時間 8,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 170 ms
19,036 KB
testcase_17 AC 169 ms
20,388 KB
testcase_18 AC 168 ms
19,108 KB
testcase_19 AC 171 ms
19,128 KB
testcase_20 AC 170 ms
20,220 KB
testcase_21 AC 171 ms
19,136 KB
testcase_22 AC 171 ms
19,020 KB
testcase_23 AC 167 ms
19,396 KB
testcase_24 AC 168 ms
20,060 KB
testcase_25 AC 169 ms
19,964 KB
testcase_26 AC 200 ms
19,472 KB
testcase_27 AC 202 ms
19,068 KB
testcase_28 AC 199 ms
19,044 KB
testcase_29 AC 202 ms
19,164 KB
testcase_30 AC 202 ms
19,120 KB
testcase_31 AC 183 ms
19,580 KB
testcase_32 AC 186 ms
19,380 KB
testcase_33 AC 187 ms
19,416 KB
testcase_34 AC 187 ms
19,324 KB
testcase_35 AC 185 ms
20,524 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 2 ms
4,384 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 50 ms
7,796 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 ConvexHull {
	deque<pair<V,V>> Q;
	const int cmptype=0;
	V calc(pair<V,V> p, V x) {
		return p.first*x+p.second;
	}
	int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) {
		return ((__int128)(B.second-C.second)*(B.first-A.first)<=(__int128)(A.second-B.second)*(C.first-B.first));
	}
	void add(V a, V b) { // add ax+b
		if(Q.size() && Q.back().first==a) {
			//aが同じ場合
			//if(b>=Q.back().second) return; //minの場合
			if(b<=Q.back().second) return; //maxの場合
			Q.pop_back();
		}
		Q.push_back({a,b});
		int v;
		while((v=Q.size())>=3 && dodo(Q[v-3],Q[v-2],Q[v-1]))
			Q[v-2]=Q[v-1], Q.pop_back();
	}
	void add(vector<pair<V,V>> v) {
		sort(v.begin(),v.end());
		for(auto r=v.begin();r!=v.end();r++) add(r->first,r->second);
	}
	
	
	V query(V x) {
		int L=-1,R=Q.size()-1;
		while(R-L>1) {
			int M=(L+R)/2;
			(cmptype^((calc(Q[M],x)<=calc(Q[M+1],x)))?L:R)=M;
		}
		return calc(Q[R],x);
	}
};
ConvexHull<double> ch;

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