結果

問題 No.545 ママの大事な二人の子供
ユーザー titiatitia
提出日時 2024-03-03 00:33:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 704 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 84,384 KB
最終ジャッジ日時 2024-03-03 00:33:10
合計ジャッジ時間 5,822 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 35 ms
53,460 KB
testcase_06 AC 34 ms
53,460 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 35 ms
53,460 KB
testcase_09 AC 35 ms
53,460 KB
testcase_10 WA -
testcase_11 AC 37 ms
53,460 KB
testcase_12 AC 35 ms
53,460 KB
testcase_13 AC 39 ms
53,460 KB
testcase_14 AC 43 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 59 ms
68,480 KB
testcase_19 AC 66 ms
73,172 KB
testcase_20 AC 82 ms
76,096 KB
testcase_21 AC 39 ms
53,460 KB
testcase_22 AC 96 ms
78,408 KB
testcase_23 AC 129 ms
83,872 KB
testcase_24 AC 77 ms
75,856 KB
testcase_25 AC 130 ms
83,872 KB
testcase_26 AC 132 ms
83,744 KB
testcase_27 AC 126 ms
83,872 KB
testcase_28 AC 134 ms
83,840 KB
testcase_29 AC 133 ms
83,872 KB
testcase_30 AC 142 ms
84,384 KB
testcase_31 AC 142 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