結果

問題 No.1239 Multiplication -2
ユーザー りあんりあん
提出日時 2020-09-03 22:07:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 104,320 KB
最終ジャッジ日時 2024-05-03 06:08:43
合計ジャッジ時間 4,087 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,456 KB
testcase_01 AC 37 ms
51,456 KB
testcase_02 AC 38 ms
51,712 KB
testcase_03 AC 52 ms
63,232 KB
testcase_04 AC 51 ms
62,848 KB
testcase_05 AC 50 ms
63,488 KB
testcase_06 AC 46 ms
60,416 KB
testcase_07 AC 48 ms
61,056 KB
testcase_08 AC 38 ms
52,480 KB
testcase_09 AC 41 ms
51,456 KB
testcase_10 AC 38 ms
51,968 KB
testcase_11 AC 38 ms
52,096 KB
testcase_12 AC 39 ms
52,096 KB
testcase_13 AC 40 ms
51,840 KB
testcase_14 AC 38 ms
52,096 KB
testcase_15 AC 73 ms
82,944 KB
testcase_16 AC 83 ms
90,368 KB
testcase_17 AC 105 ms
103,680 KB
testcase_18 AC 101 ms
103,680 KB
testcase_19 AC 104 ms
103,808 KB
testcase_20 AC 105 ms
104,320 KB
testcase_21 AC 105 ms
103,680 KB
testcase_22 AC 102 ms
103,808 KB
testcase_23 AC 89 ms
94,848 KB
testcase_24 AC 88 ms
94,720 KB
testcase_25 AC 79 ms
89,984 KB
testcase_26 AC 86 ms
92,544 KB
testcase_27 AC 71 ms
81,152 KB
testcase_28 AC 103 ms
100,352 KB
testcase_29 AC 106 ms
100,608 KB
testcase_30 AC 76 ms
85,760 KB
testcase_31 AC 86 ms
92,416 KB
testcase_32 AC 109 ms
104,064 KB
testcase_33 AC 94 ms
95,160 KB
testcase_34 AC 87 ms
92,288 KB
testcase_35 AC 72 ms
82,560 KB
testcase_36 AC 71 ms
81,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

mod = 998244353
inv = (mod + 1) // 2

n = int(input())
a = list(map(int, input().split()))
dp = [0] * 5
dp[3] = 1
p = 1
pp = pow(2, max(0, n - 2), mod)
ans = 0
for i in range(n):
    nex = [0] * 5
    for j in range(5):
        k = (j - 2) * a[i] + 2
        if not (0 <= k <= 4):
            k = 2
        nex[k] = (nex[k] + dp[j]) % mod
    nex[3] = (nex[3] + p) % mod
    p = p * 2 % mod
    dp = nex
    if i < n - 1:
        ans = (ans + dp[0] * pp) % mod
    else:
        ans = (ans + dp[0]) % mod
    pp = pp * inv % mod
print(ans * pow(2, mod - n, mod) % mod)
0