結果

問題 No.180 美しいWhitespace (2)
ユーザー 👑 rin204rin204
提出日時 2023-11-23 18:57:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,730 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,164 KB
最終ジャッジ日時 2023-11-23 18:57:40
合計ジャッジ時間 5,170 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 133 ms
73,216 KB
testcase_10 AC 134 ms
73,728 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 132 ms
73,472 KB
testcase_20 AC 37 ms
53,460 KB
testcase_21 AC 37 ms
53,460 KB
testcase_22 AC 37 ms
53,460 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 38 ms
53,460 KB
testcase_26 AC 37 ms
53,460 KB
testcase_27 AC 38 ms
53,460 KB
testcase_28 AC 37 ms
53,460 KB
testcase_29 AC 38 ms
53,460 KB
testcase_30 AC 149 ms
76,164 KB
testcase_31 AC 154 ms
76,164 KB
testcase_32 AC 84 ms
70,508 KB
testcase_33 AC 140 ms
76,028 KB
testcase_34 AC 140 ms
76,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
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]

        if l2 <= l1 <= r1:
            ma_ = A[j] * l1 + B[j]
            mi_ = A[i] * l1 + B[i]
            if ma_ - mi_ < ans:
                ans = ma_ - mi_
                x = l1
            elif ma_ - mi_ == ans and l1 < x:
                x = l1
        if l1 <= l2 <= r1:
            ma_ = A[j] * l2 + B[j]
            mi_ = A[i] * l2 + B[i]
            if ma_ - mi_ < ans:
                ans = ma_ - mi_
                x = l2
            elif ma_ - mi_ == ans and l1 < x:
                x = l2


print(x)
0