結果
| 問題 |
No.2012 Largest Triangle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-15 22:41:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,200 ms / 2,500 ms |
| コード長 | 1,887 bytes |
| コンパイル時間 | 204 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 97,664 KB |
| 最終ジャッジ日時 | 2024-06-27 21:22:16 |
| 合計ジャッジ時間 | 25,183 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 41 |
ソースコード
import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
local = False
N = int(input())
if not local:
xy = [tuple(mi()) for i in range(N)]
else:
xy = [(random.randint(-100,100),random.randint(-100,100)) for i in range(N)]
xy.sort()
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
totu = convex_hull(xy)
totu.pop()
n = len(totu)
def f(i,a,b):
i %= n
x,y = totu[i]
return a*y-b*x
res = 0
for x,y in xy:
l,m,r = 0,n,2*n
while r-l >= 3:
nl = (l+m)//2
nr = (m+r+1)//2
if f(nl,x,y) < f(m,x,y):
l,m,r = l,nl,m
elif f(m,x,y) > f(nr,x,y):
l,m,r = m,nr,r
else:
l,m,r = nl,m,nr
res = max(res,abs(f(m,x,y)))
l,m,r = 0,n,2*n
while r-l >= 3:
nl = (l+m)//2
nr = (m+r+1)//2
if -f(nl,x,y) < -f(m,x,y):
l,m,r = l,nl,m
elif -f(m,x,y) > -f(nr,x,y):
l,m,r = m,nr,r
else:
l,m,r = nl,m,nr
res = max(res,abs(f(m,x,y)))
print(res)
if local:
check = 0
for x,y in xy:
for p,q in xy:
check = max(check,abs(x*q-y*p))
print(check)