結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-08-26 10:04:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,046 ms / 5,000 ms
コード長 587 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 284,848 KB
最終ジャッジ日時 2024-04-22 02:20:47
合計ジャッジ時間 14,067 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,968 KB
testcase_01 AC 38 ms
51,712 KB
testcase_02 AC 42 ms
51,968 KB
testcase_03 AC 38 ms
51,584 KB
testcase_04 AC 38 ms
51,712 KB
testcase_05 AC 39 ms
51,968 KB
testcase_06 AC 38 ms
51,968 KB
testcase_07 AC 38 ms
52,224 KB
testcase_08 AC 75 ms
79,744 KB
testcase_09 AC 76 ms
75,520 KB
testcase_10 AC 66 ms
73,600 KB
testcase_11 AC 886 ms
91,264 KB
testcase_12 AC 1,134 ms
92,160 KB
testcase_13 AC 347 ms
91,008 KB
testcase_14 AC 1,132 ms
92,160 KB
testcase_15 AC 91 ms
90,424 KB
testcase_16 AC 523 ms
91,008 KB
testcase_17 AC 878 ms
91,776 KB
testcase_18 AC 347 ms
90,880 KB
testcase_19 AC 116 ms
90,176 KB
testcase_20 AC 161 ms
90,612 KB
testcase_21 AC 204 ms
90,240 KB
testcase_22 AC 160 ms
90,112 KB
testcase_23 AC 67 ms
78,080 KB
testcase_24 AC 67 ms
78,208 KB
testcase_25 AC 322 ms
95,652 KB
testcase_26 AC 341 ms
95,404 KB
testcase_27 AC 326 ms
95,232 KB
testcase_28 AC 334 ms
95,544 KB
testcase_29 AC 321 ms
95,232 KB
testcase_30 AC 308 ms
151,616 KB
testcase_31 AC 4,046 ms
284,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
mod=998244353
ans=pow(2,n-1,mod)*sum(a)%mod
p=999630629
k=sum(a)-p
if k>=0:
    dp=[0]*(k+1)
    dp[0]=1
    newdp=[0]*(k+1)
    ch=set()
    ch.add(0)
    for x in a:
        newch=set()
        for s in ch:
            newdp[s]+=dp[s]
            newdp[s]%=mod
            newch.add(s)
            if s+x<=k:
                newdp[s+x]+=dp[s]
                newdp[s+x]%=mod
                newch.add(s+x)
        for s in ch:dp[s]=0
        dp,newdp=newdp,dp
        ch=newch
    ans-=p*sum(dp)
print(ans%mod)



0