結果

問題 No.545 ママの大事な二人の子供
ユーザー hedwig100hedwig100
提出日時 2020-05-29 11:56:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 752 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 90,496 KB
最終ジャッジ日時 2024-04-22 16:32:07
合計ジャッジ時間 3,366 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,096 KB
testcase_01 AC 40 ms
52,096 KB
testcase_02 AC 39 ms
52,352 KB
testcase_03 AC 40 ms
52,224 KB
testcase_04 AC 38 ms
52,096 KB
testcase_05 AC 42 ms
52,224 KB
testcase_06 AC 38 ms
52,096 KB
testcase_07 AC 38 ms
51,968 KB
testcase_08 AC 39 ms
52,224 KB
testcase_09 AC 41 ms
52,096 KB
testcase_10 AC 41 ms
52,096 KB
testcase_11 AC 40 ms
52,224 KB
testcase_12 AC 41 ms
52,352 KB
testcase_13 AC 40 ms
52,224 KB
testcase_14 AC 41 ms
52,608 KB
testcase_15 AC 40 ms
52,480 KB
testcase_16 AC 45 ms
58,496 KB
testcase_17 AC 48 ms
59,264 KB
testcase_18 AC 64 ms
66,688 KB
testcase_19 AC 63 ms
67,968 KB
testcase_20 AC 69 ms
72,960 KB
testcase_21 AC 38 ms
52,224 KB
testcase_22 AC 90 ms
80,640 KB
testcase_23 AC 110 ms
89,856 KB
testcase_24 AC 88 ms
80,512 KB
testcase_25 AC 104 ms
89,856 KB
testcase_26 AC 110 ms
90,112 KB
testcase_27 AC 105 ms
90,496 KB
testcase_28 AC 112 ms
89,728 KB
testcase_29 AC 102 ms
89,856 KB
testcase_30 AC 106 ms
90,112 KB
testcase_31 AC 102 ms
89,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left,bisect_right
N = int(input())
satisf = [tuple(map(int,input().split())) for _ in range(N)]
if N == 1:
    print(min(satisf[0]))
    exit()

left = [satisf[0][0],-satisf[0][1]]
for x,y in satisf[1:int(N//2)]:
    left = [l + x for l in left] + [l - y for l in left]
right = [satisf[N//2][0],-satisf[N//2][1]]
for x,y in satisf[int(N//2) + 1:]:
    right = [r + x for r in right] + [r - y for r in right]

right = list(set(right))
right.sort()
ans = 1<<30
for l in left:
    idx = bisect_left(right,-l)
    if idx == len(right):
        ans = min(ans,abs(right[idx - 1] + l))
    elif idx == 0:
        ans = min(ans,abs(right[0] + l))
    else:
        ans = min(ans,abs(right[idx - 1] + l),abs(right[idx] + l))
print(ans)
0