結果

問題 No.2012 Largest Triangle
ユーザー 👑 kmjpkmjp
提出日時 2022-09-27 23:21:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 2,500 ms
コード長 2,226 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 216,240 KB
実行使用メモリ 20,908 KB
最終ジャッジ日時 2024-06-02 01:19:34
合計ジャッジ時間 7,334 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,948 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 155 ms
19,292 KB
testcase_17 AC 152 ms
20,336 KB
testcase_18 AC 158 ms
19,264 KB
testcase_19 AC 163 ms
19,776 KB
testcase_20 AC 157 ms
19,452 KB
testcase_21 AC 162 ms
20,116 KB
testcase_22 AC 168 ms
20,304 KB
testcase_23 AC 158 ms
19,144 KB
testcase_24 AC 162 ms
20,108 KB
testcase_25 AC 158 ms
19,444 KB
testcase_26 AC 193 ms
20,908 KB
testcase_27 AC 190 ms
20,460 KB
testcase_28 AC 189 ms
19,620 KB
testcase_29 AC 187 ms
20,392 KB
testcase_30 AC 189 ms
19,216 KB
testcase_31 AC 169 ms
19,432 KB
testcase_32 AC 170 ms
20,812 KB
testcase_33 AC 171 ms
20,376 KB
testcase_34 AC 182 ms
19,944 KB
testcase_35 AC 173 ms
19,672 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 3 ms
6,944 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 46 ms
7,924 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