結果

問題 No.545 ママの大事な二人の子供
ユーザー brthyyjpbrthyyjp
提出日時 2020-03-18 04:45:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 86,724 KB
最終ジャッジ日時 2023-08-20 19:41:15
合計ジャッジ時間 5,748 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,180 KB
testcase_01 AC 61 ms
71,240 KB
testcase_02 AC 60 ms
71,176 KB
testcase_03 AC 61 ms
71,288 KB
testcase_04 AC 60 ms
71,148 KB
testcase_05 AC 61 ms
71,464 KB
testcase_06 AC 63 ms
71,548 KB
testcase_07 AC 60 ms
71,240 KB
testcase_08 AC 60 ms
71,464 KB
testcase_09 AC 61 ms
71,416 KB
testcase_10 AC 62 ms
71,080 KB
testcase_11 AC 63 ms
71,240 KB
testcase_12 AC 62 ms
71,012 KB
testcase_13 AC 62 ms
71,328 KB
testcase_14 AC 71 ms
76,252 KB
testcase_15 AC 63 ms
71,248 KB
testcase_16 AC 73 ms
76,448 KB
testcase_17 AC 75 ms
76,700 KB
testcase_18 AC 86 ms
76,524 KB
testcase_19 AC 92 ms
77,568 KB
testcase_20 AC 90 ms
77,212 KB
testcase_21 AC 61 ms
71,380 KB
testcase_22 AC 113 ms
81,100 KB
testcase_23 AC 146 ms
86,248 KB
testcase_24 AC 102 ms
81,208 KB
testcase_25 AC 145 ms
86,460 KB
testcase_26 AC 146 ms
86,468 KB
testcase_27 AC 130 ms
86,724 KB
testcase_28 AC 148 ms
86,256 KB
testcase_29 AC 135 ms
86,388 KB
testcase_30 AC 139 ms
86,456 KB
testcase_31 AC 136 ms
86,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = [0]*n
B = [0]*n
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

p = n//2
q = n-p
A1 = A[0:p]
A2 = A[p:n]
B1 = B[0:p]
B2 = B[p:n]
D1 = []
D2 = []
for i in range(2**p):
    a = 0
    b = 0
    for j in range(p):
        if (i >> j) & 1:
            a += A1[j]
        else:
            b += B1[j]
    D1.append(a-b)

for i in range(2**q):
    a = 0
    b = 0
    for j in range(q):
        if (i >> j) & 1:
            a += A2[j]
        else:
            b += B2[j]
    D2.append(a-b)
D2.sort()
D2 = [-10**18] + D2 + [10**18]
import bisect
ans = 10**18
for d in D1:
    id = bisect.bisect_right(D2, -d)
    ans = min(ans, min(abs(D2[id-1]+d), abs(D2[id]+d)))
print(ans)
0