結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 161 ms
6,128 KB
testcase_19 AC 162 ms
6,248 KB
testcase_20 WA -
testcase_21 AC 163 ms
6,144 KB
testcase_22 AC 160 ms
6,252 KB
testcase_23 WA -
testcase_24 AC 161 ms
6,320 KB
testcase_25 AC 158 ms
6,136 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 272 ms
6,320 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 3 ms
4,380 KB
testcase_38 WA -
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 TLE -
権限があれば一括ダウンロードができます

ソースコード

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

using ll = long long;
  struct F {
    ll a, b;
    F(ll a, ll b) : a(a), b(b) {}
  };
struct ConvexHullTrick {


  deque<F> deq;

  bool check(F &f1, F &f2, F &f3) {
    return (f2.a - f1.a) * (f3.b - f2.b) >= (f2.b - f1.b) * (f3.a - f2.a);
  }

  ll f(F &f1, ll x) {
    return f1.a * x + f1.b;
  }

public:
  // a_{prev} >= a
  void add_line(ll a, ll b) {
    F f1 = F(a, b);
    while(deq.size() >= 2 && check(deq[deq.size()-2], deq[deq.size()-1], f1)) {
      deq.pop_back();
    }
    deq.push_back(f1);
  }

  // x_{prev} <= x
  ll query(ll x) {
    while(deq.size() >= 2 && f(deq[0], x) >= f(deq[1], x)) {
      deq.pop_front();
    }
    return f(deq[0], x);
  }
};

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());
	
	ConvexHullTrick C;
	rep(i,n){
		C.add_line(a[i].first,-a[i].second);
	}
	
	long long ans = 0;
	deque<pair<long long,long long>> D;
	rep(i,C.deq.size()){
		D.emplace_back(C.deq[i].a,C.deq[i].b);
	}
	
	
	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;			
		}
		
		rep(j,D.size()){
			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