結果

問題 No.180 美しいWhitespace (2)
ユーザー 👑 rin204rin204
提出日時 2023-11-23 19:04:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 404 ms / 5,000 ms
コード長 1,743 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,280 KB
最終ジャッジ日時 2023-11-23 19:04:10
合計ジャッジ時間 5,974 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 39 ms
53,460 KB
testcase_04 AC 59 ms
66,012 KB
testcase_05 AC 66 ms
68,456 KB
testcase_06 AC 69 ms
70,536 KB
testcase_07 AC 85 ms
72,608 KB
testcase_08 AC 82 ms
72,596 KB
testcase_09 AC 135 ms
73,340 KB
testcase_10 AC 162 ms
73,340 KB
testcase_11 AC 90 ms
75,768 KB
testcase_12 AC 103 ms
75,772 KB
testcase_13 AC 132 ms
75,768 KB
testcase_14 AC 137 ms
75,644 KB
testcase_15 AC 131 ms
74,108 KB
testcase_16 AC 143 ms
75,772 KB
testcase_17 AC 138 ms
74,108 KB
testcase_18 AC 133 ms
73,980 KB
testcase_19 AC 130 ms
73,596 KB
testcase_20 AC 35 ms
53,460 KB
testcase_21 AC 34 ms
53,460 KB
testcase_22 AC 34 ms
53,460 KB
testcase_23 AC 34 ms
53,460 KB
testcase_24 AC 34 ms
53,460 KB
testcase_25 AC 38 ms
53,460 KB
testcase_26 AC 37 ms
53,460 KB
testcase_27 AC 37 ms
53,460 KB
testcase_28 AC 38 ms
53,460 KB
testcase_29 AC 36 ms
53,460 KB
testcase_30 AC 206 ms
76,160 KB
testcase_31 AC 213 ms
76,160 KB
testcase_32 AC 404 ms
75,816 KB
testcase_33 AC 273 ms
76,152 KB
testcase_34 AC 295 ms
76,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
if n == 1:
    print(1)
    exit()
A = [0] * n
B = [0] * n
for i in range(n):
    B[i], A[i] = map(int, input().split())

mi = [None] * n
ma = [None] * n
for i in range(n):
    l = 1
    r = 1 << 60
    for j in range(n):
        if i == j:
            continue
        if A[i] == A[j]:
            if B[i] > B[j]:
                r = -1
                break
        elif A[i] > A[j]:
            r = min(r, (B[j] - B[i]) // (A[i] - A[j]))
        else:
            db = B[i] - B[j]
            da = A[j] - A[i]
            l = max(l, (db + da - 1) // da)

    if l <= r:
        mi[i] = (l, r)

    l = 1
    r = 1 << 60
    for j in range(n):
        if i == j:
            continue
        if A[i] == A[j]:
            if B[i] < B[j]:
                r = -1
                break
        elif A[i] > A[j]:
            da = A[i] - A[j]
            db = B[j] - B[i]
            l = max(l, (db + da - 1) // da)
        else:
            r = min(r, (B[i] - B[j]) // (A[j] - A[i]))

    if l <= r:
        ma[i] = (l, r)


ans = 1 << 60
x = 1 << 60
for i in range(n):
    if mi[i] is None:
        continue

    l1, r1 = mi[i]
    for j in range(n):
        if i == j or ma[j] is None:
            continue

        l2, r2 = ma[j]

        cand = []

        if l1 <= r2 <= r1:
            cand.append(r2)
        if l1 <= l2 <= r1:
            cand.append(l2)
        if l2 <= l1 <= r2:
            cand.append(l1)
        if l2 <= r1 <= r2:
            cand.append(r1)

        for c in cand:
            ma_ = A[j] * c + B[j]
            mi_ = A[i] * c + B[i]
            if ma_ - mi_ < ans:
                ans = ma_ - mi_
                x = c
            elif ma_ - mi_ == ans and c < x:
                x = c


print(x)
0