結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー 👑 rin204rin204
提出日時 2022-08-26 22:43:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 506 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 329,960 KB
最終ジャッジ日時 2024-04-22 00:48:38
合計ジャッジ時間 16,925 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
52,372 KB
testcase_01 AC 32 ms
52,096 KB
testcase_02 AC 34 ms
52,608 KB
testcase_03 AC 34 ms
52,224 KB
testcase_04 AC 33 ms
52,224 KB
testcase_05 AC 31 ms
52,480 KB
testcase_06 AC 31 ms
52,224 KB
testcase_07 AC 32 ms
52,224 KB
testcase_08 AC 55 ms
78,720 KB
testcase_09 AC 49 ms
74,240 KB
testcase_10 AC 47 ms
72,704 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 49 ms
76,928 KB
testcase_24 AC 47 ms
76,940 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
MOD2 = 999630629

n = int(input())
A = list(map(int, input().split()))
times = pow(2, n - 1, MOD)
ans = sum(A) * times % MOD

x = sum(A) - MOD2

if x < 0:
    print(ans)
    exit()

dp = {0:1}
A.sort(reverse = True)
for a in A:
    add = {}
    for k, v in dp.items():
        if a + k <= x:
            add[a + k] = add.get(a + k, 0) + v
    for k, v in add.items():
        dp[k] = dp.get(k, 0) + v
        dp[k] %= MOD
    

tot = sum(dp.values()) - 1
ans -= tot * MOD2
print(ans % MOD)
0