結果

問題 No.2012 Largest Triangle
ユーザー mkawa2mkawa2
提出日時 2022-07-15 23:12:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,020 ms / 2,500 ms
コード長 3,035 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 130,724 KB
最終ジャッジ日時 2023-09-10 05:53:11
合計ジャッジ時間 40,032 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,916 KB
testcase_01 AC 76 ms
71,580 KB
testcase_02 AC 79 ms
72,028 KB
testcase_03 AC 74 ms
71,888 KB
testcase_04 AC 74 ms
71,576 KB
testcase_05 AC 75 ms
71,916 KB
testcase_06 AC 74 ms
72,044 KB
testcase_07 AC 73 ms
72,012 KB
testcase_08 AC 74 ms
71,888 KB
testcase_09 AC 75 ms
71,804 KB
testcase_10 AC 75 ms
71,816 KB
testcase_11 AC 76 ms
71,820 KB
testcase_12 AC 78 ms
71,828 KB
testcase_13 AC 76 ms
71,712 KB
testcase_14 AC 77 ms
71,700 KB
testcase_15 AC 76 ms
71,768 KB
testcase_16 AC 1,935 ms
129,164 KB
testcase_17 AC 1,973 ms
129,508 KB
testcase_18 AC 1,956 ms
129,636 KB
testcase_19 AC 1,955 ms
129,256 KB
testcase_20 AC 1,939 ms
129,420 KB
testcase_21 AC 1,978 ms
129,920 KB
testcase_22 AC 2,020 ms
129,132 KB
testcase_23 AC 1,940 ms
129,232 KB
testcase_24 AC 1,958 ms
129,876 KB
testcase_25 AC 1,983 ms
130,724 KB
testcase_26 AC 1,331 ms
130,452 KB
testcase_27 AC 1,339 ms
130,320 KB
testcase_28 AC 1,355 ms
129,780 KB
testcase_29 AC 1,318 ms
130,656 KB
testcase_30 AC 1,325 ms
130,244 KB
testcase_31 AC 1,760 ms
129,556 KB
testcase_32 AC 1,757 ms
129,896 KB
testcase_33 AC 1,757 ms
129,248 KB
testcase_34 AC 1,741 ms
129,020 KB
testcase_35 AC 1,749 ms
129,260 KB
testcase_36 AC 104 ms
77,676 KB
testcase_37 AC 105 ms
77,704 KB
testcase_38 AC 110 ms
78,344 KB
testcase_39 AC 104 ms
77,708 KB
testcase_40 AC 106 ms
77,820 KB
testcase_41 AC 307 ms
94,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = 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)-1
md = 10**9+7
# md = 998244353

class Vector:
    def __init__(self, x, y, init_x=1, init_y=0):
        self.x = x
        self.y = y
        self.norm2 = x*x+y*y
        self.norm = self.norm2**0.5
        self.zone = 2
        if x == y == 0: self.zone = -1
        elif init_x*y-init_y*x > 0: self.zone = 1
        elif init_x*y-init_y*x < 0: self.zone = 3
        elif init_x*x+init_y*y > 0: self.zone = 0

    def __repr__(self):
        return "({},{})".format(self.x, self.y)

    def __eq__(self, other):
        if self.zone != other.zone: return False
        return self.outer(other) == 0

    def __lt__(self, other):
        if self.zone == other.zone: return self.outer(other) > 0
        return self.zone < other.zone

    def __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.x
        self.y += other.y
        return self

    def __isub__(self, other):
        self.x -= other.x
        self.y -= other.y
        return self

    def __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 != 0
        return Vector(self.x/val, self.y/val)

    def dot(self, v): return self.x*v.x+self.y*v.y

    def outer(self, v): return self.x*v.y-self.y*v.x

    def 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) >= 0

    res = []
    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.y
    return 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 = 0
v = vv[0]
while f(v, (j-1)%m) >= f(v, j): j = (j-1)%m

ans = 0
for v in vv:
    while f(v, (i+1)%m) > f(v, i): i = (i+1)%m
    while f(v, (j+1)%m) > f(v, j): j = (j+1)%m
    ans = max(ans, f(v, i), f(v, j))

print(ans)
0