結果

問題 No.2012 Largest Triangle
ユーザー googol_S0googol_S0
提出日時 2022-07-16 00:07:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,554 bytes
コンパイル時間 4,737 ms
コンパイル使用メモリ 272,096 KB
実行使用メモリ 7,304 KB
最終ジャッジ日時 2023-09-10 06:25:49
合計ジャッジ時間 11,341 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 212 ms
6,308 KB
testcase_17 AC 214 ms
6,388 KB
testcase_18 AC 212 ms
6,252 KB
testcase_19 AC 211 ms
6,160 KB
testcase_20 WA -
testcase_21 AC 211 ms
6,260 KB
testcase_22 AC 211 ms
6,312 KB
testcase_23 AC 211 ms
6,240 KB
testcase_24 AC 212 ms
6,196 KB
testcase_25 AC 212 ms
6,368 KB
testcase_26 AC 213 ms
7,008 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 212 ms
7,044 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 214 ms
6,180 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 56 ms
7,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//taninnno_debug
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

template <typename T>
struct CHT{
	deque<pair<T,T>> D;
	void add(T a,T b){
		while(true){
			if(D.size()<=1){
				D.emplace_back(a,b);
				break;
			}
			T a3 = a,b3 = b,a2 = D.back().first,b2 = D.back().second;
			D.pop_back();
			T a1 = D.back().first,b1 = D.back().second;
			D.pop_back();
			
			if((a2-a1)*(b3-b2)>=(b2-b1)*(a3-a2)){
				D.emplace_back(a1,b1);
				continue;
			}
			else{
				D.emplace_back(a1,b1);
				D.emplace_back(a2,b2);
				D.emplace_back(a3,b3);
				break;
			}
		}
	}

	T query(T x,T y){
		while(true){
			if(D.size()<=1)break;
			T a1 = D.front().first,b1 = D.front().second;
			D.pop_front();
			T a2 = D.front().first,b2 = D.front().second;
			if(a1*x+b1*y>=a2*x+b2*y){
				continue;
			}
			else{
				D.emplace_front(a1,b1);
				break;
			}
		}
		
		return D.front().first*x +	D.front().second*y;
	}
};

bool check(long long a0,long long b0,long long a1,long long b1,long long x,long long y){
	
	return (a0-a1)*x < (b1-b0)*y;
	
}

int main(){
	
	int n;
	cin>>n;
	vector<pair<long long,long long>> a(n);
	rep(i,n){
		cin>>a[i].first>>a[i].second;
		swap(a[i].first,a[i].second);
	}
	sort(a.begin(),a.end());
	
	CHT<long long> C1,C2,C3,C4;
    CHT<long long> D1,D2,D3,D4;
 	rep(i,n){
		C1.add(a[i].first,-a[i].second);
        C2.add(a[i].first,-a[i].second);
        C3.add(a[i].first,-a[i].second);
        C4.add(a[i].first,-a[i].second);
	}
    rep(i,n){
        D1.add(a[i].first,-a[i].second);
        D2.add(a[i].first,-a[i].second);
        D3.add(a[i].first,-a[i].second);
        D4.add(a[i].first,-a[i].second);
    }
	rep(i,n){
		swap(a[i].first,a[i].second);
	}
	sort(a.begin(),a.end(),[](pair<long long,long long> x,pair<long long,long long> y){
		return x.first*y.second<x.second*y.first;
	});
	
	long long ans = 0;
	
	
	
	rep(i,n){
        if((a[i].first>=0)&&(a[i].second>=0)){ans = min(ans,min(C1.query(a[i].first,a[i].second),D1.query(-a[i].first,-a[i].second)));}
        else if((a[i].first>=0)){ans = min(ans,min(C2.query(a[i].first,a[i].second),D2.query(-a[i].first,-a[i].second)));}
        else if((a[i].first<0)&&(a[i].second<0)){ans = min(ans,min(C3.query(a[i].first,a[i].second),D3.query(-a[i].first,-a[i].second)));}
        else{ans = min(ans,min(C4.query(a[i].first,a[i].second),D4.query(-a[i].first,-a[i].second)));}
	}
	
	cout<<-ans<<endl;
	
    return 0;
}
0