結果

問題 No.1645 AB's abs
ユーザー LyricalMaestroLyricalMaestro
提出日時 2024-01-24 01:53:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,936 KB
最終ジャッジ日時 2024-01-24 01:53:51
合計ジャッジ時間 5,558 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 57 ms
68,192 KB
testcase_03 AC 43 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 60 ms
70,248 KB
testcase_09 AC 61 ms
72,296 KB
testcase_10 AC 57 ms
70,264 KB
testcase_11 AC 59 ms
70,244 KB
testcase_12 AC 59 ms
70,252 KB
testcase_13 AC 103 ms
75,632 KB
testcase_14 AC 88 ms
75,504 KB
testcase_15 AC 104 ms
75,632 KB
testcase_16 AC 102 ms
75,752 KB
testcase_17 AC 105 ms
75,616 KB
testcase_18 AC 93 ms
75,628 KB
testcase_19 AC 98 ms
75,616 KB
testcase_20 AC 89 ms
75,500 KB
testcase_21 AC 96 ms
75,504 KB
testcase_22 AC 101 ms
75,632 KB
testcase_23 AC 96 ms
75,612 KB
testcase_24 AC 99 ms
75,500 KB
testcase_25 AC 103 ms
75,628 KB
testcase_26 AC 98 ms
75,628 KB
testcase_27 AC 106 ms
75,632 KB
testcase_28 AC 104 ms
75,628 KB
testcase_29 AC 103 ms
75,632 KB
testcase_30 AC 106 ms
76,004 KB
testcase_31 AC 103 ms
75,616 KB
testcase_32 AC 107 ms
76,012 KB
testcase_33 AC 134 ms
77,936 KB
testcase_34 AC 127 ms
77,664 KB
testcase_35 AC 127 ms
77,932 KB
testcase_36 AC 131 ms
77,792 KB
testcase_37 AC 126 ms
77,928 KB
testcase_38 AC 44 ms
59,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1645

MOD = 998244353

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

    max_a = sum([abs(a) for a in A])

    dp = {0:1}
    for a in A:
        new_dp = {}
        for key, value in dp.items():
            if (key + a) not in new_dp:
                new_dp[key + a] = 0
            new_dp[key + a] += value
            new_dp[key + a] %= MOD

            if (key - a) not in new_dp:
                new_dp[key - a] = 0
            new_dp[key - a] += value
            new_dp[key - a] %= MOD
        dp = new_dp

    answer = 0    
    for key, value in dp.items():
        k = abs(key)
        answer += (k * value) % MOD
        answer %= MOD

    print(answer)


if __name__ == "__main__":
    main()
0