結果

問題 No.2012 Largest Triangle
ユーザー shotoyooshotoyoo
提出日時 2022-07-16 00:06:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 954 ms / 2,500 ms
コード長 2,197 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 128,552 KB
最終ジャッジ日時 2023-09-10 06:24:51
合計ジャッジ時間 22,937 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
74,056 KB
testcase_01 AC 115 ms
74,476 KB
testcase_02 AC 117 ms
74,224 KB
testcase_03 AC 114 ms
74,452 KB
testcase_04 AC 116 ms
74,080 KB
testcase_05 AC 117 ms
74,244 KB
testcase_06 AC 116 ms
74,288 KB
testcase_07 AC 118 ms
74,444 KB
testcase_08 AC 115 ms
74,008 KB
testcase_09 AC 115 ms
74,292 KB
testcase_10 AC 115 ms
74,260 KB
testcase_11 AC 118 ms
74,480 KB
testcase_12 AC 118 ms
74,460 KB
testcase_13 AC 119 ms
74,304 KB
testcase_14 AC 117 ms
74,320 KB
testcase_15 AC 117 ms
74,220 KB
testcase_16 AC 844 ms
122,148 KB
testcase_17 AC 954 ms
128,536 KB
testcase_18 AC 871 ms
122,252 KB
testcase_19 AC 853 ms
121,744 KB
testcase_20 AC 846 ms
121,688 KB
testcase_21 AC 827 ms
121,788 KB
testcase_22 AC 841 ms
122,376 KB
testcase_23 AC 954 ms
128,024 KB
testcase_24 AC 836 ms
122,224 KB
testcase_25 AC 954 ms
128,084 KB
testcase_26 AC 746 ms
121,800 KB
testcase_27 AC 736 ms
121,760 KB
testcase_28 AC 856 ms
128,036 KB
testcase_29 AC 734 ms
121,732 KB
testcase_30 AC 726 ms
121,956 KB
testcase_31 AC 836 ms
122,208 KB
testcase_32 AC 912 ms
128,372 KB
testcase_33 AC 841 ms
121,936 KB
testcase_34 AC 824 ms
121,704 KB
testcase_35 AC 952 ms
128,552 KB
testcase_36 AC 148 ms
81,072 KB
testcase_37 AC 149 ms
81,116 KB
testcase_38 AC 149 ms
81,244 KB
testcase_39 AC 147 ms
81,104 KB
testcase_40 AC 149 ms
81,024 KB
testcase_41 AC 320 ms
92,744 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
xy.sort(key=lambda item: item[0])
t = CHT()
t2 = CHT()
for x,y in xy:
    t.add(-x,y)
for x,y in xy[::-1]:
    t2.add(x, -y)
xy.sort(key=lambda item: item[1]/item[0])
ans = 0
for x,y in xy:
    v = t.query(y/x)
    v2 = -t2.query(y/x)
    if x<0:
        ans = max(ans, x*v)
    else:
        ans = max(ans, x*v2)
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