結果

問題 No.180 美しいWhitespace (2)
ユーザー mkawa2mkawa2
提出日時 2020-01-27 10:04:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,792 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 11,080 KB
実行使用メモリ 8,496 KB
最終ジャッジ日時 2023-10-12 12:50:35
合計ジャッジ時間 2,065 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,416 KB
testcase_01 AC 16 ms
8,260 KB
testcase_02 AC 16 ms
8,284 KB
testcase_03 AC 16 ms
8,224 KB
testcase_04 AC 17 ms
8,196 KB
testcase_05 AC 17 ms
8,248 KB
testcase_06 AC 18 ms
8,368 KB
testcase_07 AC 19 ms
8,368 KB
testcase_08 AC 21 ms
8,040 KB
testcase_09 AC 25 ms
8,096 KB
testcase_10 AC 25 ms
8,148 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 25 ms
8,124 KB
testcase_20 AC 16 ms
8,444 KB
testcase_21 WA -
testcase_22 AC 16 ms
8,260 KB
testcase_23 AC 16 ms
8,120 KB
testcase_24 AC 16 ms
8,252 KB
testcase_25 AC 15 ms
8,288 KB
testcase_26 AC 15 ms
8,356 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 16 ms
8,404 KB
testcase_30 AC 24 ms
8,496 KB
testcase_31 WA -
testcase_32 AC 24 ms
8,152 KB
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def isl(m):
        mx0 = mx1 = 0
        mn0 = mn1 = inf
        for a, b in zip(aa, bb):
            v = a + b * (m - 1)
            if v > mx0: mx0 = v
            if v < mn0: mn0 = v
            v = a + b * m
            if v > mx1: mx1 = v
            if v < mn1: mn1 = v
        return mx0 - mn0 > mx1 - mn1

    def f(x):
        mx = 0
        mn = inf
        for a, b in zip(aa, bb):
            v = a + b * x
            if v > mx: mx = v
            if v < mn: mn = v
        return mx - mn

    inf = 10 ** 9 + 1
    n = II()
    aa = []
    bb = []
    for _ in range(n):
        a, b = MI()
        aa.append(a)
        bb.append(b)
    # y=a+bxとして、f(x)=max(y)-min(y)は下に凸の関数になる
    # 下に凸の関数の最小値は三分探索が一般的だが、今回はxが整数という制約があるので二分探索でいける
    # あるx1と、その左隣のx0(つまりx0=x1-1)があったとき
    # f(x0)>f(x1)となれば最小値をとるxはもっと右
    # そうでなければ最小値をとるxはもっと左となる
    l = 1
    r = inf
    while l + 1 < r:
        m = (l + r) // 2
        if isl(m): l = m
        else: r = m
    # 一応lrの前後を含めて確認
    mn = inf
    ans = l
    for x in range(max(1, l - 1), r + 2):
        v = f(x)
        if v < mn:
            ans = x
            mn = v
    print(ans)

main()
0