結果
問題 | No.2012 Largest Triangle |
ユーザー |
![]() |
提出日時 | 2022-07-15 23:12:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,991 ms / 2,500 ms |
コード長 | 3,035 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 128,512 KB |
最終ジャッジ日時 | 2024-06-27 21:25:57 |
合計ジャッジ時間 | 38,268 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 41 |
ソースコード
import syssys.setrecursionlimit(200005)int1 = lambda x: int(x)-1pDB = lambda *x: print(*x, end="\n", file=sys.stderr)p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)def II(): return int(sys.stdin.readline())def LI(): return list(map(int, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LI1(): return list(map(int1, sys.stdin.readline().split()))def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def SI(): return sys.stdin.readline().rstrip()# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]inf = (1 << 63)-1# inf = (1 << 31)-1md = 10**9+7# md = 998244353class Vector:def __init__(self, x, y, init_x=1, init_y=0):self.x = xself.y = yself.norm2 = x*x+y*yself.norm = self.norm2**0.5self.zone = 2if x == y == 0: self.zone = -1elif init_x*y-init_y*x > 0: self.zone = 1elif init_x*y-init_y*x < 0: self.zone = 3elif init_x*x+init_y*y > 0: self.zone = 0def __repr__(self):return "({},{})".format(self.x, self.y)def __eq__(self, other):if self.zone != other.zone: return Falsereturn self.outer(other) == 0def __lt__(self, other):if self.zone == other.zone: return self.outer(other) > 0return self.zone < other.zonedef __add__(self, other): return Vector(self.x+other.x, self.y+other.y)def __sub__(self, other): return Vector(self.x-other.x, self.y-other.y)def __iadd__(self, other):self.x += other.xself.y += other.yreturn selfdef __isub__(self, other):self.x -= other.xself.y -= other.yreturn selfdef __neg__(self):return Vector(-self.x, -self.y)def __mul__(self, val):return Vector(val*self.x, val*self.y)__rmul__ = __mul__def __truediv__(self, val):assert val != 0return Vector(self.x/val, self.y/val)def dot(self, v): return self.x*v.x+self.y*v.ydef outer(self, v): return self.x*v.y-self.y*v.xdef rot90(self): return Vector(-self.y, self.x)def ConvexHull(xy):def NG(x, y):x0, y0 = res[-2]x1, y1 = res[-1]return (x-x0)*(y1-y0)-(x1-x0)*(y-y0) >= 0res = []xy.sort()for x, y in xy:while len(res) > 1 and NG(x, y): res.pop()res.append((x, y))under_n = len(res)for x, y in xy[-2::-1]:while len(res) > under_n and NG(x, y): res.pop()res.append((x, y))return res[:-1]def f(v, i):s, t = st[i]x, y = v.x, v.yreturn abs(y*s-x*t)n = II()xy = LLI(n)st = ConvexHull(xy)m = len(st)vv = [Vector(x, y) for x, y in xy]vv.sort()i = j = 0v = vv[0]while f(v, (j-1)%m) >= f(v, j): j = (j-1)%mans = 0for v in vv:while f(v, (i+1)%m) > f(v, i): i = (i+1)%mwhile f(v, (j+1)%m) > f(v, j): j = (j+1)%mans = max(ans, f(v, i), f(v, j))print(ans)