結果

問題 No.545 ママの大事な二人の子供
ユーザー tobusakanatobusakana
提出日時 2023-11-01 02:52:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 81,796 KB
実行使用メモリ 103,132 KB
最終ジャッジ日時 2023-11-01 02:53:02
合計ジャッジ時間 4,548 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,548 KB
testcase_01 AC 38 ms
53,548 KB
testcase_02 AC 37 ms
53,548 KB
testcase_03 AC 37 ms
53,548 KB
testcase_04 AC 37 ms
53,548 KB
testcase_05 AC 37 ms
53,548 KB
testcase_06 AC 38 ms
53,548 KB
testcase_07 AC 37 ms
53,548 KB
testcase_08 AC 37 ms
53,548 KB
testcase_09 AC 38 ms
53,548 KB
testcase_10 AC 37 ms
53,548 KB
testcase_11 AC 38 ms
53,548 KB
testcase_12 AC 38 ms
53,548 KB
testcase_13 AC 42 ms
59,292 KB
testcase_14 AC 44 ms
59,892 KB
testcase_15 AC 37 ms
53,548 KB
testcase_16 AC 49 ms
62,164 KB
testcase_17 AC 54 ms
64,268 KB
testcase_18 AC 64 ms
70,768 KB
testcase_19 AC 66 ms
73,488 KB
testcase_20 AC 77 ms
76,300 KB
testcase_21 AC 54 ms
53,548 KB
testcase_22 AC 101 ms
86,424 KB
testcase_23 AC 155 ms
101,364 KB
testcase_24 AC 103 ms
86,424 KB
testcase_25 AC 149 ms
101,432 KB
testcase_26 AC 154 ms
101,364 KB
testcase_27 AC 152 ms
101,364 KB
testcase_28 AC 156 ms
101,364 KB
testcase_29 AC 170 ms
101,364 KB
testcase_30 AC 158 ms
103,132 KB
testcase_31 AC 148 ms
101,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

AB1 = AB[:N // 2]
AB2 = AB[N // 2:]

def f(X):
    n = len(X)
    res = []
    for status in range(1 << n):
        val = 0
        for i in range(n):
            if (status >> i) & 1:
                val += X[i][0]
            else:
                val -= X[i][1]
        res.append(val)
    return res
    
AB1 = set(f(AB1))
AB2 = sorted(set(f(AB2)))

import bisect
INF = 1 << 60
ans = INF
for val in AB1:
    # -valに一番近い数をAB2から探す
    ind = bisect.bisect_left(AB2, -val)
    if ind - 1 >= 0:
        ans = min(ans, abs(AB2[ind - 1] + val))
    if ind < len(AB2):
        ans = min(ans, abs(AB2[ind] + val))
print(ans)    
0