結果

問題 No.2331 Maximum Quadrilateral
ユーザー とりゐとりゐ
提出日時 2023-05-29 22:50:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,419 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 71,696 KB
最終ジャッジ日時 2023-08-28 00:01:02
合計ジャッジ時間 5,962 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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()
convex=convex_hull(xy)[:-1]
assert len(convex)>=3
if len(convex)==3:
  xy=convex+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(convex)
xy=convex+convex

memo=[[-10**9]*n for i in range(n)]
for L in range(n):
  tmp=L+1
  for R in range(L,L+n):
    if tmp+1!=R and calc(L,R,tmp)<calc(L,R,tmp+1):
      tmp+=1
    memo[L][R%n]=calc(L,R,tmp)

ans=0
for i in range(n):
  for j in range(i+1,n):
    ans=max(ans,memo[i][j]+memo[j][i])

print(ans)
0