結果

問題 No.2012 Largest Triangle
ユーザー shotoyooshotoyoo
提出日時 2022-07-16 00:10:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,345 ms / 2,500 ms
コード長 2,109 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 144,708 KB
最終ジャッジ日時 2023-09-10 06:31:00
合計ジャッジ時間 32,149 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
74,348 KB
testcase_01 AC 114 ms
74,260 KB
testcase_02 AC 111 ms
73,676 KB
testcase_03 AC 112 ms
74,328 KB
testcase_04 AC 111 ms
74,296 KB
testcase_05 AC 111 ms
74,072 KB
testcase_06 AC 112 ms
74,088 KB
testcase_07 AC 111 ms
74,160 KB
testcase_08 AC 114 ms
73,992 KB
testcase_09 AC 112 ms
74,132 KB
testcase_10 AC 113 ms
74,264 KB
testcase_11 AC 113 ms
74,356 KB
testcase_12 AC 114 ms
74,264 KB
testcase_13 AC 113 ms
74,296 KB
testcase_14 AC 115 ms
73,844 KB
testcase_15 AC 114 ms
74,344 KB
testcase_16 AC 1,305 ms
144,124 KB
testcase_17 AC 1,305 ms
138,408 KB
testcase_18 AC 1,345 ms
144,164 KB
testcase_19 AC 1,321 ms
144,296 KB
testcase_20 AC 1,249 ms
139,656 KB
testcase_21 AC 1,291 ms
144,708 KB
testcase_22 AC 1,310 ms
142,884 KB
testcase_23 AC 1,272 ms
135,768 KB
testcase_24 AC 1,339 ms
144,456 KB
testcase_25 AC 1,289 ms
137,624 KB
testcase_26 AC 1,300 ms
139,200 KB
testcase_27 AC 1,292 ms
139,336 KB
testcase_28 AC 1,275 ms
132,820 KB
testcase_29 AC 1,319 ms
139,724 KB
testcase_30 AC 1,319 ms
138,920 KB
testcase_31 AC 1,299 ms
139,156 KB
testcase_32 AC 1,282 ms
133,044 KB
testcase_33 AC 1,304 ms
139,872 KB
testcase_34 AC 1,311 ms
139,724 KB
testcase_35 AC 1,295 ms
133,668 KB
testcase_36 AC 149 ms
81,580 KB
testcase_37 AC 155 ms
81,628 KB
testcase_38 AC 152 ms
81,764 KB
testcase_39 AC 146 ms
81,508 KB
testcase_40 AC 144 ms
80,980 KB
testcase_41 AC 317 ms
99,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, random
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(3*10**5+10)

write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); inf=10**18
LI = lambda : list(map(int, input().split()))
def debug(_l_):
    for s in _l_.split():
        print(f"{s}={eval(s)}", end=" ")
    print()
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]

from collections import deque
class CHT:
    """傾きが単調減少かつ評価点が単調増加のときの最小値クエリ
    """
    def __init__(self):
        self.q = deque()
    @staticmethod
    def _val(t,x):
        return t[0]*x+t[1]
    @staticmethod
    def _check(t1,t2,t3):
        return (t2[0]-t1[0]) * (t3[1]-t2[1]) >= (t2[1]-t1[1]) * (t3[0]-t2[0])
    def add(self, a, b):
        """a*x + bの追加
        """
        t = (a,b)
        while len(self.q)>=2 and self._check(self.q[-2], self.q[-1], t):
            # 追加する線分と最後から2番めの線分のCHだけで凸包になる
            self.q.pop()
        self.q.append(t)
    def query(self, x):
        """a*x+bの最小値を返す
        """
        while len(self.q)>=2 and self._val(self.q[0], x) >= self._val(self.q[1], x):
            self.q.popleft()
        return self._val(self.q[0], x)
    
n = int(input())
xy = [LI() for _ in range(n)]
zx = None
zy = None
nxy = []
mx = my = 0
for x,y in xy:
    mx = max(mx, abs(x))
    my = max(my, abs(y))
    if x==0:
        zx = (x,y)
    elif y==0:
        zy = (x,y)
    else:
        nxy.append((x,y))
xy = nxy
nxy = xy + [(-x,-y) for x,y in xy]
nxy.sort(key=lambda item: item[0])
t = CHT()
for x,y in nxy:
    t.add(-x,y)
xy.sort(key=lambda item: item[1]/item[0])
ans = 0
for x,y in xy:
    v = t.query(y/x)
    ans = max(ans, abs(x*v))
if zx is not None:
    ans = max(ans, abs(zx[1])*mx)
if zy is not None:
    ans = max(ans, abs(zy[0])*my)
print(int(ans+0.01))
0