結果

問題 No.2918 Divide Applicants Fairly
ユーザー 高橋ゆに高橋ゆに
提出日時 2024-09-18 04:59:00
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,034 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 81,928 KB
実行使用メモリ 83,944 KB
最終ジャッジ日時 2024-10-07 11:31:21
合計ジャッジ時間 6,766 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 WA -
testcase_03 AC 40 ms
53,760 KB
testcase_04 AC 40 ms
53,936 KB
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 42 ms
54,272 KB
testcase_11 AC 41 ms
54,144 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 39 ms
53,760 KB
testcase_16 AC 39 ms
53,632 KB
testcase_17 RE -
testcase_18 AC 36 ms
53,632 KB
testcase_19 WA -
testcase_20 AC 38 ms
53,376 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 WA -
testcase_24 AC 39 ms
53,888 KB
testcase_25 AC 40 ms
53,760 KB
testcase_26 WA -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 39 ms
53,760 KB
testcase_31 WA -
testcase_32 AC 39 ms
53,632 KB
testcase_33 RE -
testcase_34 AC 39 ms
53,632 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 WA -
testcase_38 RE -
testcase_39 AC 39 ms
53,504 KB
testcase_40 RE -
testcase_41 AC 175 ms
81,956 KB
testcase_42 RE -
testcase_43 AC 38 ms
53,504 KB
testcase_44 AC 38 ms
53,504 KB
testcase_45 AC 37 ms
53,760 KB
testcase_46 AC 37 ms
53,760 KB
testcase_47 AC 37 ms
54,144 KB
testcase_48 WA -
testcase_49 AC 192 ms
82,008 KB
testcase_50 RE -
testcase_51 WA -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 WA -
testcase_56 WA -
testcase_57 RE -
testcase_58 WA -
testcase_59 RE -
testcase_60 RE -
testcase_61 AC 110 ms
77,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
from collections import defaultdict

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

def clc_sums(rates):
    M = len(rates)
    rate_sums = defaultdict(lambda: [])
    
    for comb in range(3 ** M):
        balance, rate_sum = 0, 0
        for i in range(M):
            sgn = (comb // (3 ** i)) % 3
            if sgn == 2: sgn = -1
            balance += sgn
            rate_sum += sgn * rates[i]
        rate_sums[balance].append(rate_sum)
    
    for balance in range(-M, M + 1):
        rate_sums[balance].sort()
    
    return rate_sums

rates = list(map(int, input().split()))

front_sums = clc_sums(rates[:N // 2])
back_sums = clc_sums(rates[N // 2:])

ans = 2 ** 30
for balance in range(-N // 2, N // 2):
    for front_sum in front_sums[balance]:
        i = bisect_left(back_sums[-balance], -front_sum)
        if i > 0: ans = min(ans, abs(front_sum - back_sums[-balance][i - 1]))
        if i < N - N // 2: ans = min(ans, abs(front_sum - back_sums[-balance][i + 1]))
print(ans)
0