結果

問題 No.3697 実力を揃える
コンテスト
ユーザー titia
提出日時 2026-10-28 03:56:56
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 781 ms / 5,000 ms
+ 251µs
コード長 783 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 142 ms
コンパイル使用メモリ 64,540 KB
実行使用メモリ 90,668 KB
最終ジャッジ日時 2026-10-28 03:57:07
合計ジャッジ時間 8,087 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from bisect import bisect

N=int(input())
A=list(map(int,input().split()))

SUM=sum(A)

B=A[:N//2]
C=A[N//2:]

XB=[[] for i in range(N//2+1)]
for i in range(1<<len(B)):
    score=0
    count=0
    for j in range(len(B)):
        if i & (1<<j) != 0:
            score+=B[j]
            count+=1

    XB[count].append(score)

for i in range(len(XB)):
    XB[i].sort()

ANS=1<<63
for i in range(1<<len(C)):
    score=0
    count=0
    for j in range(len(C)):
        if i & (1<<j) != 0:
            score+=C[j]
            count+=1
    k=N//2-count

    need=SUM//2-score

    xx=bisect(XB[k],need)

    for ix in range(xx-1,xx+1):
        if 0<=ix<len(XB[k]):
            p=score+XB[k][ix]

            ANS=min(ANS,abs(p-(SUM-p)))

print(ANS)



0