結果

問題 No.2012 Largest Triangle
ユーザー googol_S0googol_S0
提出日時 2022-07-15 23:04:46
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,735 bytes
コンパイル時間 994 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 92,444 KB
最終ジャッジ日時 2023-09-10 04:35:54
合計ジャッジ時間 12,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from decimal import *
def sgn(x):
  if x==0:
    return 0
  if x>0:
    return 1
  return -1

def check(a,b,c):
  #if a==b or b==c:
  #  return sgn(b[0]-a[0])*sgn(c[1]-b[1])>=sgn(c[0]-b[0])*sgn(b[1]-a[1])
  return (b[0]-a[0])*(c[1]-b[1])>=(c[0]-b[0])*(b[1]-a[1])

def get_y(a,x):
  return a[0]*x+a[1]

from collections import deque
class CHT:
  __slots__=['H','F']
  def __init__(self,f):
    self.H=deque()
    self.F=f
  
  def add(self,x):
    h=self.H
    if self.F:
      x=(-x[0],-x[1])
    if len(h)==0:
      h.append(x)
      return 0
    if h[0][0]<=x[0]:
      if h[0][0]==x[0]:
        if h[0][1]<=x[1]:
          return 0
        h.popleft()
      while(len(h)>=2 and check(x,h[0],h[1])):
        h.popleft()
      h.appendleft(x)
    else:
      if(h[-1][0]==x[0]):
        if(h[-1][1]<=x[1]):
          return 0
        h.pop()
      while(len(h)>=2 and check(h[-2],h[-1],x)):
        h.pop()
      h.append(x)
  
  def query_i(self,x):
    h=self.H
    a=h[0]
    if len(h)>=2:
      b=h[1]
      while(len(h)>=2 and a[0]*x+a[1]>=b[0]*x+b[1]):
        h.popleft()
        a=b
        if len(h)<2:
          break
        b=h[1]
    if self.F:
      return -a[0]*x-a[1]
    else:
      return a[0]*x+a[1]

getcontext().prec=30
Decimal=lambda x:x
N=int(input())
eps=Decimal('1e-12')
X=[tuple(map(lambda x:Decimal(int(x)+eps),input().split())) for i in range(N)]
A=CHT(True)
B=CHT(False)
X.sort(key=lambda x:x[1])
for i in range(N):
  a,b=X[i][0],X[i][1]
  A.add((b,-a))
  B.add((b,-a))
X.sort(key=lambda x:x[0]/x[1])
ANS=0
for i in range(N):
  a,b=X[i][0],X[i][1]
  x,y=B.query_i(a/b),A.query_i(a/b)
  ANS=max(ANS,-x*b,-y*b,x*b,y*b)
  if b>=0:
    ANS=max(ANS,x*b,-y*b)
  else:
    ANS=max(ANS,-x*b,y*b)
print(round(ANS))
0