結果

問題 No.2918 Divide Applicants Fairly
ユーザー みうねみうね
提出日時 2024-09-20 19:39:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,179 ms / 2,000 ms
コード長 1,265 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 82,128 KB
実行使用メモリ 98,384 KB
最終ジャッジ日時 2024-10-07 21:06:25
合計ジャッジ時間 10,436 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,236 KB
testcase_01 AC 44 ms
54,812 KB
testcase_02 AC 42 ms
53,940 KB
testcase_03 AC 42 ms
53,824 KB
testcase_04 AC 42 ms
54,820 KB
testcase_05 AC 43 ms
54,232 KB
testcase_06 AC 46 ms
59,712 KB
testcase_07 AC 42 ms
54,308 KB
testcase_08 AC 43 ms
54,316 KB
testcase_09 AC 98 ms
76,420 KB
testcase_10 AC 42 ms
55,212 KB
testcase_11 AC 529 ms
97,492 KB
testcase_12 AC 105 ms
76,512 KB
testcase_13 AC 50 ms
62,284 KB
testcase_14 AC 46 ms
58,960 KB
testcase_15 AC 42 ms
54,004 KB
testcase_16 AC 42 ms
54,360 KB
testcase_17 AC 103 ms
76,268 KB
testcase_18 AC 532 ms
98,256 KB
testcase_19 AC 42 ms
55,740 KB
testcase_20 AC 403 ms
80,824 KB
testcase_21 AC 106 ms
76,324 KB
testcase_22 AC 43 ms
54,532 KB
testcase_23 AC 99 ms
76,264 KB
testcase_24 AC 43 ms
55,312 KB
testcase_25 AC 1,179 ms
98,384 KB
testcase_26 AC 44 ms
54,244 KB
testcase_27 AC 219 ms
80,700 KB
testcase_28 AC 47 ms
59,656 KB
testcase_29 AC 51 ms
61,804 KB
testcase_30 AC 43 ms
54,796 KB
testcase_31 AC 69 ms
71,588 KB
testcase_32 AC 42 ms
54,596 KB
testcase_33 AC 43 ms
54,208 KB
testcase_34 AC 42 ms
53,824 KB
testcase_35 AC 43 ms
54,424 KB
testcase_36 AC 198 ms
80,852 KB
testcase_37 AC 164 ms
77,108 KB
testcase_38 AC 119 ms
76,960 KB
testcase_39 AC 42 ms
54,896 KB
testcase_40 AC 100 ms
76,640 KB
testcase_41 AC 135 ms
76,528 KB
testcase_42 AC 148 ms
80,388 KB
testcase_43 AC 238 ms
80,688 KB
testcase_44 AC 280 ms
95,956 KB
testcase_45 AC 521 ms
96,208 KB
testcase_46 AC 43 ms
55,460 KB
testcase_47 AC 42 ms
54,816 KB
testcase_48 AC 96 ms
76,100 KB
testcase_49 AC 159 ms
76,820 KB
testcase_50 AC 42 ms
54,488 KB
testcase_51 AC 91 ms
76,336 KB
testcase_52 AC 124 ms
77,392 KB
testcase_53 AC 93 ms
76,276 KB
testcase_54 AC 93 ms
76,200 KB
testcase_55 AC 108 ms
75,980 KB
testcase_56 AC 105 ms
76,192 KB
testcase_57 AC 217 ms
80,608 KB
testcase_58 AC 106 ms
76,128 KB
testcase_59 AC 115 ms
76,228 KB
testcase_60 AC 54 ms
63,012 KB
testcase_61 AC 111 ms
76,060 KB
testcase_62 AC 110 ms
76,724 KB
testcase_63 AC 105 ms
76,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
from collections import defaultdict

N = int(input())
    
if N > 25:
    print(0)
    exit()

rates = list(map(int, input().split()))
rate_sums = defaultdict(lambda: [])

def frontexh(i, dif, rate_sum):
    if i == N // 2:
        rate_sums[dif].append(rate_sum)
    else:
        frontexh(i + 1, dif, rate_sum)
        frontexh(i + 1, dif + 1, rate_sum + rates[i])
        frontexh(i + 1, dif - 1, rate_sum - rates[i])

frontexh(0, 0, 0)

if rate_sums[0]: rate_sums[0].pop(0)
for dif in range(-N, N + 1): rate_sums[dif].sort()

ans = 2 ** 30

has_anyone = False

def backexh(i, dif, rate_sum):
    global ans, has_anyone
    if i == N - N // 2:
        if dif == 0:
            if has_anyone:
                ans = min(ans, abs(rate_sum))
            else:
                has_anyone = True
        it = bisect_left(rate_sums[-dif], -rate_sum)
        if it < len(rate_sums[dif]):
            ans = min(ans, abs(rate_sum + rate_sums[-dif][it]))
        if it > 0:
            ans = min(ans, abs(rate_sum + rate_sums[-dif][it - 1]))
    else:
        backexh(i + 1, dif, rate_sum)
        backexh(i + 1, dif + 1, rate_sum + rates[N // 2 + i])
        backexh(i + 1, dif - 1, rate_sum - rates[N // 2 + i])

backexh(0, 0, 0)
print(ans)
0