結果
問題 | 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,bisectfrom collections import deque,defaultdictfrom heapq import heapify,heappop,heappushfrom itertools import permutationsfrom math import log,gcdinput = lambda :sys.stdin.readline().rstrip()mi = lambda :map(int,input().split())li = lambda :list(mi())local = FalseN = 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), ...]: ソートされた座標listdef 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 qstotu = convex_hull(xy)totu.pop()n = len(totu)def f(i,a,b):i %= nx,y = totu[i]return a*y-b*xres = 0for x,y in xy:l,m,r = 0,n,2*nwhile r-l >= 3:nl = (l+m)//2nr = (m+r+1)//2if f(nl,x,y) < f(m,x,y):l,m,r = l,nl,melif f(m,x,y) > f(nr,x,y):l,m,r = m,nr,relse:l,m,r = nl,m,nrres = max(res,abs(f(m,x,y)))l,m,r = 0,n,2*nwhile r-l >= 3:nl = (l+m)//2nr = (m+r+1)//2if -f(nl,x,y) < -f(m,x,y):l,m,r = l,nl,melif -f(m,x,y) > -f(nr,x,y):l,m,r = m,nr,relse:l,m,r = nl,m,nrres = max(res,abs(f(m,x,y)))print(res)if local:check = 0for x,y in xy:for p,q in xy:check = max(check,abs(x*q-y*p))print(check)