結果

問題 No.545 ママの大事な二人の子供
ユーザー lloyzlloyz
提出日時 2022-10-17 00:09:30
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 774 bytes
コンパイル時間 481 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 95,364 KB
最終ジャッジ日時 2023-09-10 01:13:24
合計ジャッジ時間 6,320 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,160 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 73 ms
71,192 KB
testcase_04 AC 72 ms
71,136 KB
testcase_05 AC 74 ms
71,256 KB
testcase_06 RE -
testcase_07 AC 73 ms
71,320 KB
testcase_08 AC 72 ms
71,180 KB
testcase_09 AC 74 ms
71,064 KB
testcase_10 AC 73 ms
71,260 KB
testcase_11 AC 74 ms
71,184 KB
testcase_12 AC 73 ms
71,272 KB
testcase_13 AC 75 ms
71,156 KB
testcase_14 AC 81 ms
76,388 KB
testcase_15 AC 74 ms
70,932 KB
testcase_16 AC 86 ms
76,340 KB
testcase_17 RE -
testcase_18 AC 100 ms
76,960 KB
testcase_19 AC 100 ms
77,584 KB
testcase_20 RE -
testcase_21 AC 71 ms
71,108 KB
testcase_22 RE -
testcase_23 AC 191 ms
95,076 KB
testcase_24 RE -
testcase_25 AC 193 ms
94,940 KB
testcase_26 AC 192 ms
95,052 KB
testcase_27 AC 191 ms
94,700 KB
testcase_28 RE -
testcase_29 AC 192 ms
95,060 KB
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
import sys
input = sys.stdin.readline

n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]

n1 = n // 2
P1 = []
for bit in range(1 << n1):
    res = 0
    for i in range(n1):
        if (bit >> i) & 1:
            res += AB[i][0]
        else:
            res -= AB[i][1]
    P1.append(res)
P1 = sorted(set(P1))
m1 = len(P1)

n2 = n - n1
P2 = []
for bit in range(1 << n2):
    res = 0
    for i in range(n2):
        if (bit >> i) & 1:
            res += AB[n1 + i][0]
        else:
            res -= AB[n1 + i][1]
    P2.append(res)
P2 = sorted(set(P2))
m2 = len(P2)

ans = 10**18
for i in range(m1):
    p1 = P1[i]
    idx = bisect_left(P2, -p1)
    ans = min(ans, abs(p1 + P2[idx - 1]), abs(p1 + P2[idx]))
print(ans)
0