結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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 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 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 166 ms
6,212 KB
testcase_19 AC 166 ms
6,300 KB
testcase_20 WA -
testcase_21 AC 166 ms
6,212 KB
testcase_22 AC 164 ms
6,200 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 166 ms
6,360 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 162 ms
6,396 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 3 ms
4,376 KB
testcase_38 WA -
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

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,long long y) {
    return f1.a * x + f1.b*y;
  }

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,ll y) {
    while(deq.size() >= 2 && f(deq[0], x, y) >= f(deq[1], x, y)) {
      deq.pop_front();
    }
    return f(deq[0], x, 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());
	
	ConvexHullTrick C;
	rep(i,n){
		C.add_line(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){
		ans = min(ans,C.query(a[i].first,a[i].second));
	}
	
	cout<<-ans<<endl;
	
    return 0;
}
0