結果

問題 No.2012 Largest Triangle
ユーザー 沙耶花沙耶花
提出日時 2022-07-15 21:57:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,905 bytes
コンパイル時間 4,612 ms
コンパイル使用メモリ 270,428 KB
実行使用メモリ 6,732 KB
最終ジャッジ日時 2023-09-10 01:40:35
合計ジャッジ時間 10,958 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,388 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 163 ms
6,164 KB
testcase_17 AC 162 ms
6,300 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 162 ms
6,164 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 164 ms
6,240 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 205 ms
6,408 KB
testcase_27 AC 205 ms
6,732 KB
testcase_28 AC 206 ms
6,436 KB
testcase_29 AC 205 ms
6,540 KB
testcase_30 WA -
testcase_31 AC 180 ms
6,204 KB
testcase_32 AC 182 ms
6,180 KB
testcase_33 WA -
testcase_34 AC 181 ms
6,116 KB
testcase_35 AC 181 ms
6,304 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 WA -
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 56 ms
4,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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){
		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>=a2*x+b2){
				continue;
			}
			else{
				D.emplace_front(a1,b1);
				break;
			}
		}
		
		return D.front().first*x +	D.front().second;
	}
};

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.rbegin(),a.rend());
	
	CHT<long long> C;
	rep(i,n){
		C.add(a[i].first,-a[i].second);
	}
	
	long long ans = 0;
	deque<pair<long long,long long>> D = C.D;
	rep(i,n){
		
		int l = 0,r = D.size()-1;
		while(r-l>3){
			int m0 = l + (r-l)/3;
			int m1 = l + (r-l)/3 * 2;
			
			if(check(D[m0].first,D[m0].second,D[m1].first,D[m1].second,a[i].second,a[i].first))r = m1;
			else l = m0;			
		}
		
		for(int j=l;j<=r;j++){
			long long cur = 0;
			cur += D[j].second * a[i].first;
			cur += D[j].first * a[i].second;
			ans = min(ans,cur);
		}
	}
	
	cout<<-ans<<endl;
	
    return 0;
}
0