結果

問題 No.2331 Maximum Quadrilateral
ユーザー qibqib
提出日時 2023-05-29 22:50:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,650 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 76,460 KB
最終ジャッジ日時 2023-08-28 00:01:09
合計ジャッジ時間 6,592 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
76,452 KB
testcase_01 AC 83 ms
75,896 KB
testcase_02 AC 86 ms
75,900 KB
testcase_03 AC 90 ms
76,460 KB
testcase_04 AC 91 ms
75,620 KB
testcase_05 AC 92 ms
76,140 KB
testcase_06 AC 86 ms
76,028 KB
testcase_07 AC 88 ms
75,484 KB
testcase_08 AC 88 ms
75,540 KB
testcase_09 AC 83 ms
75,524 KB
testcase_10 AC 89 ms
75,548 KB
testcase_11 AC 78 ms
71,136 KB
testcase_12 AC 84 ms
75,468 KB
testcase_13 AC 84 ms
75,420 KB
testcase_14 AC 86 ms
75,896 KB
testcase_15 AC 75 ms
70,712 KB
testcase_16 AC 82 ms
75,416 KB
testcase_17 AC 76 ms
71,144 KB
testcase_18 AC 82 ms
75,992 KB
testcase_19 AC 74 ms
70,828 KB
testcase_20 AC 89 ms
75,748 KB
testcase_21 AC 88 ms
75,988 KB
testcase_22 AC 89 ms
75,556 KB
testcase_23 AC 90 ms
75,440 KB
testcase_24 AC 89 ms
76,060 KB
testcase_25 AC 73 ms
71,164 KB
testcase_26 AC 72 ms
71,060 KB
testcase_27 AC 70 ms
71,168 KB
testcase_28 AC 71 ms
70,960 KB
testcase_29 AC 72 ms
71,232 KB
testcase_30 AC 70 ms
70,916 KB
testcase_31 AC 71 ms
71,092 KB
testcase_32 AC 70 ms
71,144 KB
testcase_33 AC 70 ms
71,096 KB
testcase_34 AC 71 ms
71,160 KB
testcase_35 AC 70 ms
70,992 KB
testcase_36 AC 71 ms
71,152 KB
testcase_37 AC 70 ms
71,156 KB
testcase_38 AC 70 ms
71,176 KB
testcase_39 AC 69 ms
71,164 KB
testcase_40 AC 70 ms
70,920 KB
testcase_41 AC 71 ms
71,060 KB
testcase_42 AC 68 ms
70,992 KB
testcase_43 AC 71 ms
70,940 KB
testcase_44 AC 71 ms
71,160 KB
testcase_45 AC 70 ms
71,160 KB
testcase_46 AC 70 ms
71,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 1 << 60

def cross(ux, uy, vx, vy):
  return vy * ux - vx * uy

n = int(input())
points = [list(map(int, input().split())) for _ in range(n)]

points.sort()

conv = []
for i in range(n):
  x, y = points[i]
  while len(conv) >= 2:
    ux = conv[-2][0] - conv[-1][0]
    uy = conv[-2][1] - conv[-1][1]
    vx = conv[-1][0] - x
    vy = conv[-1][1] - y
    if cross(ux, uy, vx, vy) > 0:
      conv.pop()
    else:
      break

  conv.append((x, y))

for i in range(len(points) - 2, -1, -1):
  x, y = points[i]
  while len(conv) >= 2:
    ux = conv[-2][0] - conv[-1][0]
    uy = conv[-2][1] - conv[-1][1]
    vx = conv[-1][0] - x
    vy = conv[-1][1] - y
    if cross(ux, uy, vx, vy) > 0:
      conv.pop()
    else:
      break

  conv.append((x, y))

conv.pop()

ans = - INF

if len(conv) == 3:
  for c in range(n):
    if tuple(points[c]) in conv:
      continue
    xc, yc = points[c]
    q = []
    for d in range(3):
      xi, yi = conv[d]
      xj, yj = conv[(d + 1) % 3]
      area = abs((yj - yc) * (xi - xc) - (xj - xc) * (yi - yc))
      q.append(area)

    q.sort()
    ans = max(ans, q[-2] + q[-1])

  print(ans)
  exit()

for l in range(len(conv)):
  xl, yl = conv[l]
  for j in range(len(conv) - 3):
    mid = (l + j + 2) % len(conv)
    xm, ym = conv[mid]
    al = - INF
    ar = - INF
    flg = False
    for k in range(len(conv) - 1):
      r = (l + k + 1) % len(conv)
      if r == mid:
        flg = True
        continue
      xr, yr = conv[r]
      area = abs((yr - yl) * (xm - xl) - (xr - xl) * (ym - yl))
      if flg:
        ar = max(ar, area)
      else:
        al = max(al, area)

    ans = max(ans, al + ar)

print(ans)
0