結果

問題 No.2331 Maximum Quadrilateral
ユーザー とりゐとりゐ
提出日時 2023-05-28 14:46:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 86,556 KB
実行使用メモリ 75,636 KB
最終ジャッジ日時 2023-08-27 10:33:57
合計ジャッジ時間 6,319 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
70,984 KB
testcase_01 AC 79 ms
70,996 KB
testcase_02 AC 87 ms
75,164 KB
testcase_03 AC 88 ms
75,348 KB
testcase_04 AC 88 ms
75,244 KB
testcase_05 AC 89 ms
75,636 KB
testcase_06 AC 83 ms
71,372 KB
testcase_07 AC 86 ms
75,320 KB
testcase_08 AC 85 ms
75,356 KB
testcase_09 AC 81 ms
70,916 KB
testcase_10 AC 85 ms
75,012 KB
testcase_11 AC 80 ms
71,372 KB
testcase_12 AC 82 ms
71,136 KB
testcase_13 AC 81 ms
71,248 KB
testcase_14 AC 81 ms
71,212 KB
testcase_15 AC 76 ms
71,108 KB
testcase_16 AC 80 ms
71,144 KB
testcase_17 AC 76 ms
71,404 KB
testcase_18 AC 78 ms
71,336 KB
testcase_19 AC 77 ms
71,084 KB
testcase_20 AC 86 ms
75,096 KB
testcase_21 AC 85 ms
75,360 KB
testcase_22 AC 85 ms
75,112 KB
testcase_23 AC 87 ms
75,376 KB
testcase_24 AC 83 ms
71,304 KB
testcase_25 AC 74 ms
71,288 KB
testcase_26 AC 73 ms
71,320 KB
testcase_27 AC 74 ms
71,012 KB
testcase_28 AC 74 ms
71,292 KB
testcase_29 AC 74 ms
71,320 KB
testcase_30 AC 75 ms
70,920 KB
testcase_31 AC 73 ms
71,160 KB
testcase_32 AC 75 ms
71,280 KB
testcase_33 AC 74 ms
71,080 KB
testcase_34 AC 73 ms
71,116 KB
testcase_35 AC 76 ms
71,304 KB
testcase_36 AC 75 ms
71,136 KB
testcase_37 AC 73 ms
70,868 KB
testcase_38 AC 74 ms
70,920 KB
testcase_39 AC 74 ms
71,208 KB
testcase_40 AC 75 ms
71,084 KB
testcase_41 AC 74 ms
71,156 KB
testcase_42 AC 77 ms
71,128 KB
testcase_43 AC 73 ms
71,140 KB
testcase_44 AC 73 ms
71,448 KB
testcase_45 AC 74 ms
71,300 KB
testcase_46 AC 75 ms
71,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
xy=[]
for _ in range(n):
  x,y=map(int,input().split())
  xy.append((x,y))

def cross3(a, b, c):
    return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])

# ps = [(x, y), ...]: ソートされた座標list
def convex_hull(ps):
    qs = []
    N = len(ps)
    for p in ps:
        # 一直線上で高々2点にする場合は ">=" にする
        while len(qs) > 1 and cross3(qs[-1], qs[-2], p) >= 0:
            qs.pop()
        qs.append(p)
    t = len(qs)
    for i in range(N-2, -1, -1):
        p = ps[i]
        while len(qs) > t and cross3(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    return qs

def calc(L,R,mid):
  x1,y1=xy[L]
  x2,y2=xy[R]
  x3,y3=xy[mid]
  dx1=x3-x1
  dy1=y3-y1
  dx2=x2-x1
  dy2=y2-y1
  return -abs(dy1*dx2-dx1*dy2)

xy.sort()
cxy=convex_hull(xy)[:-1]
assert len(cxy)>=3
if len(cxy)==3:
  xy=cxy+xy
  n=len(xy)
  ans=0
  for i in range(3):
    p=i
    q=(i+1)%3
    r=(i+2)%3
    for j in range(3,n):
      if xy[j] not in [xy[p],xy[q],xy[r]]:
        ans=max(ans,-calc(p,q,j)-calc(q,r,j))
  print(ans)
  exit()
  
n=len(cxy)

xy=cxy+cxy

def get(L,R):
  l=L
  r=R
  while l+2<r:
    c1=l+(r-l)//3
    c2=r-(r-l)//3
    if calc(L,R,c1)<calc(L,R,c2):
      r=c2
    else:
      l=c1
  ans=10**18
  for i in range(l,r+1):
    ans=min(ans,calc(L,R,i))
  return -ans


ans=0
for i in range(n):
  for j in range(i+2,n):
    ans=max(ans,get(i,j)+get(j,i+n))
    
print(ans)
0