結果

問題 No.545 ママの大事な二人の子供
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-24 00:32:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 490 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 79,608 KB
最終ジャッジ日時 2023-10-21 15:23:52
合計ジャッジ時間 3,502 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,492 KB
testcase_01 AC 38 ms
53,492 KB
testcase_02 AC 38 ms
53,492 KB
testcase_03 AC 38 ms
53,492 KB
testcase_04 AC 38 ms
53,492 KB
testcase_05 AC 38 ms
53,492 KB
testcase_06 AC 38 ms
53,492 KB
testcase_07 AC 37 ms
53,492 KB
testcase_08 AC 38 ms
53,492 KB
testcase_09 AC 37 ms
53,492 KB
testcase_10 AC 39 ms
53,492 KB
testcase_11 AC 38 ms
53,492 KB
testcase_12 AC 40 ms
53,492 KB
testcase_13 AC 40 ms
53,492 KB
testcase_14 AC 41 ms
53,492 KB
testcase_15 AC 38 ms
53,492 KB
testcase_16 AC 46 ms
61,664 KB
testcase_17 AC 53 ms
64,284 KB
testcase_18 AC 58 ms
66,368 KB
testcase_19 AC 59 ms
68,420 KB
testcase_20 AC 64 ms
72,720 KB
testcase_21 AC 39 ms
53,492 KB
testcase_22 AC 79 ms
76,296 KB
testcase_23 AC 99 ms
78,100 KB
testcase_24 AC 78 ms
76,316 KB
testcase_25 AC 93 ms
78,024 KB
testcase_26 AC 100 ms
78,100 KB
testcase_27 AC 90 ms
79,344 KB
testcase_28 AC 100 ms
78,096 KB
testcase_29 AC 96 ms
79,608 KB
testcase_30 AC 91 ms
78,104 KB
testcase_31 AC 88 ms
78,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
from itertools import product
n = int(input())
m = n // 2
AB = tuple(tuple(map(int, input().split())) for _ in range(n))
A, _ = zip(*AB)
sumA = sum(A)


X = [0]
Y = [0]
for a, b in AB[:m]:
    X.extend([x+a+b for x in X])
for a, b in AB[m:]:
    Y.extend([y+a+b for y in Y])


Y.sort()
ans = 10**18
for x in X:
    T = sumA - x
    i = bisect.bisect_left(Y, T)
    for j in range(-3, 4):
        if 0 <= i + j < len(Y):
            ans = min(ans, abs(T - Y[i + j]))
print(ans)
0