結果

問題 No.2918 Divide Applicants Fairly
ユーザー 高橋ゆに高橋ゆに
提出日時 2024-09-18 19:21:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,338 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 81,336 KB
最終ジャッジ日時 2024-10-07 11:31:36
合計ジャッジ時間 6,685 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 40 ms
54,400 KB
testcase_02 AC 41 ms
53,888 KB
testcase_03 AC 42 ms
53,888 KB
testcase_04 AC 45 ms
54,128 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 43 ms
53,632 KB
testcase_11 AC 43 ms
53,632 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 47 ms
58,880 KB
testcase_15 AC 43 ms
53,888 KB
testcase_16 AC 43 ms
53,632 KB
testcase_17 WA -
testcase_18 AC 43 ms
54,144 KB
testcase_19 WA -
testcase_20 AC 42 ms
53,888 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 43 ms
53,504 KB
testcase_25 AC 44 ms
53,504 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 42 ms
53,888 KB
testcase_31 WA -
testcase_32 AC 43 ms
53,812 KB
testcase_33 AC 43 ms
53,760 KB
testcase_34 AC 43 ms
54,272 KB
testcase_35 AC 45 ms
53,760 KB
testcase_36 AC 208 ms
80,504 KB
testcase_37 AC 172 ms
77,312 KB
testcase_38 AC 125 ms
77,312 KB
testcase_39 AC 44 ms
54,016 KB
testcase_40 AC 112 ms
76,800 KB
testcase_41 AC 158 ms
76,800 KB
testcase_42 AC 172 ms
80,512 KB
testcase_43 AC 43 ms
53,760 KB
testcase_44 AC 44 ms
54,144 KB
testcase_45 AC 43 ms
54,272 KB
testcase_46 AC 43 ms
53,504 KB
testcase_47 AC 43 ms
53,888 KB
testcase_48 WA -
testcase_49 AC 163 ms
77,628 KB
testcase_50 AC 42 ms
54,016 KB
testcase_51 AC 93 ms
76,672 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 97 ms
76,544 KB
testcase_55 AC 112 ms
76,672 KB
testcase_56 AC 120 ms
76,416 KB
testcase_57 WA -
testcase_58 AC 113 ms
76,416 KB
testcase_59 AC 118 ms
76,544 KB
testcase_60 WA -
testcase_61 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
from collections import defaultdict

N = int(input())
    
if N > 22:
    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

for rate_sum in rate_sums[0]:
    ans = min(ans, abs(rate_sum))

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, 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