結果

問題 No.2012 Largest Triangle
ユーザー 👑 potato167potato167
提出日時 2022-07-15 22:26:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,135 bytes
コンパイル時間 2,577 ms
コンパイル使用メモリ 217,564 KB
実行使用メモリ 13,008 KB
最終ジャッジ日時 2023-09-10 03:03:41
合計ジャッジ時間 9,709 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 239 ms
12,508 KB
testcase_17 AC 249 ms
12,524 KB
testcase_18 AC 247 ms
12,536 KB
testcase_19 AC 253 ms
12,520 KB
testcase_20 AC 243 ms
12,600 KB
testcase_21 AC 248 ms
12,552 KB
testcase_22 WA -
testcase_23 AC 239 ms
12,536 KB
testcase_24 AC 240 ms
12,576 KB
testcase_25 WA -
testcase_26 AC 233 ms
12,884 KB
testcase_27 AC 239 ms
12,796 KB
testcase_28 AC 237 ms
13,008 KB
testcase_29 AC 236 ms
12,852 KB
testcase_30 WA -
testcase_31 AC 235 ms
12,484 KB
testcase_32 AC 235 ms
12,532 KB
testcase_33 AC 235 ms
12,452 KB
testcase_34 AC 235 ms
12,644 KB
testcase_35 AC 247 ms
12,416 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 62 ms
5,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}

bool det(pair<ll,ll> a,pair<ll,ll> b,pair<ll,ll> c){
	a.first-=b.first;
	a.second-=b.second;
	b.first-=c.first;
	b.second-=c.second;
	return (0<a.first*b.second-a.second*b.first);
}

bool _2d_comp(pair<ll,ll> &l,pair<ll,ll> &r){
	if(l.first==0&&r.first==0) return l.second>r.second;
	if(l.first==0){
		return l.second>0||r.first<0;
	}
	if(r.first==0){
		return !(r.second>0||l.first<0);
	}
	if((l.first<0)^(r.first<0)) return l.first>0;
	return l.first*r.second<l.second*r.first;
}


void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N;
	cin>>N;
	vector<pair<ll,ll>> p(N);
	rep(i,N) cin>>p[i].first>>p[i].second;
	vector<ll> X(N),Y(N);
	So(p);
	rep(i,N) tie(X[i],Y[i])=p[i];
	auto f=[&](int a,int b)->ll{
		return abs(p[a].first*p[b].second-p[a].second*p[b].first);
	};
	if(N<=4000){
		ll ans=0;
		rep(i,N) rep(j,i) chmax(ans,f(i,j));
		cout<<ans<<"\n";
		return ;
	}
	vector<int> conv(N*2);
	int k=0;
	rep(i,N){
		while(k>1&&det(p[conv[k-2]],p[conv[k-1]],p[i])){
			k--;
		}
		conv[k]=i;
		k++;
	}
	int t=k;
	for(int i=N-2;i>=0;i--){
		while(k>t&&det(p[conv[k-2]],p[conv[k-1]],p[conv[i]])){
			k--;
		}
		conv[k]=i;
		k++;
	}
	conv.resize(k);
	int x=0;
	vector<int> order(N*2+k);
	rep(i,N*2+k) order[i]=i;
	auto sub_p=[](pair<ll,ll> a,pair<ll,ll> b)->pair<ll,ll>{
		return {a.first-b.first,a.second-b.second};
	};
	sort(all(order),[&](int l,int r){
		pair<ll,ll> L,R;
		if(l<N) L=p[l];
		else if(l<N*2) L={X[l-N]*-1,Y[l-N]*-1};
		else L=sub_p(p[conv[l-N*2]],p[conv[(l-N*2+k-1)%k]]);
		if(r<N) R=p[r];
		else if(r<N*2) R={X[r-N]*-1,Y[r-N]*-1};
		else R=sub_p(p[conv[r-N*2]],p[conv[(r-N*2+k-1)%k]]);
		return _2d_comp(L,R);
	});
	ll ans=0;
	if(k<4000){
		rep(i,k) rep(j,i){
			chmax(ans,f(conv[j],conv[i]));
		}
	}
	if(k<200){
		rep(i,k) rep(j,N){
			chmax(ans,f(conv[i],j));
		}
	}
	rep(i,N*4+k*2){
		int v=order[i%(N*2+k)];
		if(v<N*2){
			v%=N;
			chmax(ans,f(v,x));
		}else{
			x=conv[v-N*2];
		}
	}
	cout<<ans<<"\n";
}
0