結果

問題 No.2331 Maximum Quadrilateral
ユーザー tnakao0123tnakao0123
提出日時 2023-06-27 15:01:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,172 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 60,980 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-17 12:07:31
合計ジャッジ時間 2,263 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2331.cc:  No.2331 Maximum Quadrilateral - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

/* typedef */

template <typename T>
struct Pt {
  T x, y;
  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt<T> &p) : x(p.x), y(p.y) {}

  Pt<T> operator+(const Pt<T> p) const { return Pt<T>(x + p.x, y + p.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt<T> p) const { return Pt<T>(x - p.x, y - p.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt<T> v) const { return x * v.x + y * v.y; }
  T cross(Pt<T> v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt<T> p) { return Pt<T>((x + p.x) / 2, (y + p.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }

  bool operator==(const Pt<T> pt) const { return x == pt.x && y == pt.y; }
  bool operator<(const Pt<T> &pt) const {
    return x < pt.x || (x == pt.x && y < pt.y);
  }
};

typedef Pt<int> pt;
typedef vector<pt> vpt;

/* global variables */

/* subroutines */

void convex_hull(const vpt& ps, vpt& chs) {
  int n = ps.size();
  vpt lhs, uhs;

  lhs.push_back(ps[0]);
  lhs.push_back(ps[1]);
  for (int i = 2; i < n; i++) {
    while (lhs.size() >= 2) {
      int ln = lhs.size();
      pt &lh0 = lhs[ln - 2], &lh1 = lhs[ln - 1];
      if ((lh1 - lh0).cross(ps[i] - lh1) > 0) break;
      lhs.pop_back();
    }
    lhs.push_back(ps[i]);
  }

  uhs.push_back(ps[n - 1]);
  uhs.push_back(ps[n - 2]);
  for (int i = n - 3; i >= 0; i--) {
    while (uhs.size() >= 2) {
      int un = uhs.size();
      pt &uh0 = uhs[un - 2], &uh1 = uhs[un - 1];
      if ((uh1 - uh0).cross(ps[i] - uh1) > 0) break;
      uhs.pop_back();
    }
    uhs.push_back(ps[i]);
  }

  lhs.pop_back();
  uhs.pop_back();

  chs.clear();
  chs.reserve(lhs.size() + uhs.size());
  chs.assign(lhs.begin(), lhs.end());
  chs.insert(chs.end(), uhs.begin(), uhs.end());
}

inline int area(pt &p0, pt &p1, pt &p2) {
  return abs((p1 - p0).cross(p2 - p0));
}

int tsearch(vpt &chs, int i, int j0, int l0, int r0) {
  int m = chs.size(), j = (i + j0) % m;

  while (l0 + 2 < r0) {
    int kk0 = (l0 * 2 + r0) / 3;
    int kk1 = (l0 + r0 * 2) / 3;
    int s0 = area(chs[i], chs[j], chs[(i + kk0) % m]);
    int s1 = area(chs[i], chs[j], chs[(i + kk1) % m]);
    if (s0 < s1) l0 = kk0;
    else r0 = kk1;
  }

  int maxs = 0;
  for (int k = l0; k <= r0; k++)
    maxs = max(maxs, area(chs[i], chs[j], chs[(i + k) % m]));

  return maxs;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  vpt ps(n);
  for (int i = 0; i < n; i++) scanf("%d%d", &ps[i].x, &ps[i].y);
  sort(ps.begin(), ps.end());

  vpt chs;
  convex_hull(ps, chs);
  int m = chs.size();
  //printf("m=%d\n", m);
  //for (auto &p: chs) printf("%d, %d\n", p.x, p.y);

  int maxs = 0;
  for (int i = 0; i < m; i++) {
    for (int j0 = 2; j0 + 2 <= m; j0++) {
      int t0 = tsearch(chs, i, j0, 1, j0 - 1);
      int t1 = tsearch(chs, i, j0, j0 + 1, m - 1);
      maxs = max(maxs, t0 + t1);
    }
  }

  printf("%d\n", maxs);

  return 0;
}
0