結果
| 問題 | 
                            No.2012 Largest Triangle
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Kiri8128
                         | 
                    
| 提出日時 | 2021-06-10 02:20:16 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 918 ms / 2,500 ms | 
| コード長 | 1,799 bytes | 
| コンパイル時間 | 296 ms | 
| コンパイル使用メモリ | 82,172 KB | 
| 実行使用メモリ | 118,008 KB | 
| 最終ジャッジ日時 | 2024-06-27 21:17:12 | 
| 合計ジャッジ時間 | 19,862 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 41 | 
ソースコード
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
class CHT(): # Convex Hull Trick, Sorted Lines, Sorted Queries, Min Query
    # add_line は a の降順
    # query は x の昇順
    def __init__(self):
        self.Q = deque()
    
    def calc(self, f, x):
        return f[0] * x + f[1]
    
    def check(self, f1, f2, f3):
        return (f2[0] - f1[0]) * (f3[1] - f2[1]) >= (f2[1] - f1[1]) * (f3[0] - f2[0])
    
    def add_line(self, a, b):
        f = (a, b)
        if len(self.Q) and self.Q[-1][0] == a:
            if self.Q[-1][1] > b:
                self.Q.pop()
            else:
                return
        
        while len(self.Q) >= 2 and self.check(self.Q[-2], self.Q[-1], f):
            self.Q.pop()
        self.Q.append(f)
    
    def query(self, x):
        while len(self.Q) >= 2 and self.calc(self.Q[0], x) >= self.calc(self.Q[1], x):
            self.Q.popleft()
        return self.calc(self.Q[0], x)
def calc(n, X):
    x_y0 = 0
    for i, (x, y) in enumerate(X):
        if y == 0:
            x_y0 = x
            del X[i]
            break
    ans = 0
    if x_y0:
        may = 0
        for x, y in X:
            may = max(may, abs(y))
        ans = abs(x_y0) * may
    
    X.sort(key = lambda x: x[1])
    cht1 = CHT()
    for x, y in X:
        cht1.add_line(-y, x)
    cht2 = CHT()
    for x, y in X[::-1]:
        cht2.add_line(y, -x)
    X = [(x, y, x / y) for x, y in X]
    X.sort(key = lambda x: x[2])
    for x, y, z in X:
        ans = max(ans, y * cht1.query(z) if y < 0 else -y * cht2.query(z))
    return round(ans)
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append((x, y))
print(calc(N, X))
            
            
            
        
            
Kiri8128