結果

問題 No.2012 Largest Triangle
ユーザー 👑 potato167potato167
提出日時 2022-07-15 22:11:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,748 bytes
コンパイル時間 2,620 ms
コンパイル使用メモリ 216,900 KB
実行使用メモリ 11,224 KB
最終ジャッジ日時 2023-09-10 02:13:32
合計ジャッジ時間 7,393 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 RE -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 124 ms
10,900 KB
testcase_17 AC 126 ms
10,920 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 125 ms
10,876 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 123 ms
10,832 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 150 ms
11,164 KB
testcase_27 WA -
testcase_28 AC 151 ms
11,192 KB
testcase_29 AC 152 ms
11,160 KB
testcase_30 WA -
testcase_31 AC 121 ms
10,804 KB
testcase_32 AC 121 ms
10,984 KB
testcase_33 WA -
testcase_34 AC 122 ms
10,852 KB
testcase_35 AC 122 ms
10,944 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 WA -
testcase_41 AC 44 ms
5,092 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];
	vector<int> conv(N);
	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+k);
	rep(i,N+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 L=sub_p(p[conv[l-N]],p[conv[(l-N+k-1)%k]]);
		if(r<N) R=p[r];
		else R=sub_p(p[conv[r-N]],p[conv[(r-N+k-1)%k]]);
		return _2d_comp(L,R);
	});
	ll ans=0;
	rep(i,N*2+k*2){
		int v=order[i%(N+k)];
		if(v<N){
			pair<ll,ll> A=p[v],B=p[conv[x]];
			chmax(ans,abs(A.first*B.second-A.second*B.first));
		}else{
			x=v-N;
		}
	}
	cout<<ans<<"\n";
}
0