結果

問題 No.545 ママの大事な二人の子供
ユーザー titiatitia
提出日時 2024-03-03 00:35:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 84,384 KB
最終ジャッジ日時 2024-03-03 00:35:56
合計ジャッジ時間 3,830 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 36 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 40 ms
53,460 KB
testcase_12 AC 37 ms
53,460 KB
testcase_13 AC 37 ms
53,460 KB
testcase_14 AC 44 ms
62,240 KB
testcase_15 AC 36 ms
53,460 KB
testcase_16 AC 47 ms
62,240 KB
testcase_17 AC 49 ms
64,312 KB
testcase_18 AC 60 ms
68,480 KB
testcase_19 AC 68 ms
73,172 KB
testcase_20 AC 84 ms
76,096 KB
testcase_21 AC 36 ms
53,460 KB
testcase_22 AC 97 ms
78,408 KB
testcase_23 AC 130 ms
83,872 KB
testcase_24 AC 78 ms
75,856 KB
testcase_25 AC 147 ms
83,872 KB
testcase_26 AC 130 ms
83,744 KB
testcase_27 AC 126 ms
83,872 KB
testcase_28 AC 134 ms
83,872 KB
testcase_29 AC 132 ms
83,872 KB
testcase_30 AC 140 ms
84,384 KB
testcase_31 AC 140 ms
84,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect

n=int(input())

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

B0=B[:n//2]
B1=B[n//2:]

X=[]
Y=[]

for i in range(1<<len(B0)):
    score=0

    for j in range(len(B0)):
        if i & (1<<j) != 0:
            score+=B0[j][0]
        else:
            score-=B0[j][1]

    X.append(score)


for i in range(1<<len(B1)):
    score=0

    for j in range(len(B1)):
        if i & (1<<j) != 0:
            score+=B1[j][0]
        else:
            score-=B1[j][1]

    Y.append(score)


X.sort()
Y.sort()

ind=len(Y)-1

ANS=1<<60

for i in range(len(X)):
    while ind-1>=0 and abs(X[i]+Y[ind])>=abs(X[i]+Y[ind-1]):
        ind-=1

    ANS=min(ANS,abs(X[i]+Y[ind]))

print(ANS)
0