結果

問題 No.545 ママの大事な二人の子供
ユーザー 👑 rin204rin204
提出日時 2022-10-31 23:01:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 513 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 111,224 KB
最終ジャッジ日時 2023-09-22 19:53:16
合計ジャッジ時間 5,261 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,252 KB
testcase_01 AC 74 ms
71,260 KB
testcase_02 AC 72 ms
71,228 KB
testcase_03 AC 74 ms
71,432 KB
testcase_04 AC 74 ms
71,436 KB
testcase_05 AC 72 ms
71,232 KB
testcase_06 AC 73 ms
71,272 KB
testcase_07 AC 73 ms
71,540 KB
testcase_08 AC 74 ms
71,272 KB
testcase_09 AC 73 ms
71,052 KB
testcase_10 AC 74 ms
71,132 KB
testcase_11 AC 72 ms
71,452 KB
testcase_12 AC 74 ms
71,364 KB
testcase_13 AC 73 ms
71,268 KB
testcase_14 AC 74 ms
71,348 KB
testcase_15 AC 75 ms
71,272 KB
testcase_16 AC 79 ms
75,364 KB
testcase_17 AC 80 ms
75,396 KB
testcase_18 AC 89 ms
76,336 KB
testcase_19 AC 91 ms
76,468 KB
testcase_20 AC 95 ms
77,292 KB
testcase_21 AC 71 ms
71,340 KB
testcase_22 AC 118 ms
89,372 KB
testcase_23 AC 158 ms
110,796 KB
testcase_24 AC 120 ms
90,164 KB
testcase_25 AC 154 ms
111,212 KB
testcase_26 AC 155 ms
111,172 KB
testcase_27 AC 156 ms
111,224 KB
testcase_28 AC 157 ms
110,848 KB
testcase_29 AC 154 ms
110,888 KB
testcase_30 AC 159 ms
111,212 KB
testcase_31 AC 155 ms
111,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

n = int(input())
lst = []
for _ in range(n):
    a, b = map(int, input().split())
    lst.append((a, b))

L = lst[:n//2]
R = lst[n//2:]

def f(A):
    ret = {0}
    for a, b in A:
        nex = set()
        for s in ret:
            nex.add(s + a)
            nex.add(s - b)
        ret = nex
    return sorted(ret)

L = f(L)
R = [-1 << 60] + f(R) + [1 << 60]

ans = 1 << 60
for l in L:
    l *= -1
    p = bisect_left(R, l)
    ans = min(ans, l - R[p - 1], R[p] - l)

print(ans)
0