結果

問題 No.1239 Multiplication -2
ユーザー りあんりあん
提出日時 2020-09-03 22:07:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 105,528 KB
最終ジャッジ日時 2023-08-15 19:22:51
合計ジャッジ時間 5,516 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,332 KB
testcase_01 AC 61 ms
71,356 KB
testcase_02 AC 60 ms
71,180 KB
testcase_03 AC 84 ms
76,920 KB
testcase_04 AC 72 ms
76,788 KB
testcase_05 AC 74 ms
76,920 KB
testcase_06 AC 68 ms
76,536 KB
testcase_07 AC 71 ms
76,656 KB
testcase_08 AC 62 ms
71,412 KB
testcase_09 AC 61 ms
71,276 KB
testcase_10 AC 61 ms
71,360 KB
testcase_11 AC 61 ms
71,336 KB
testcase_12 AC 70 ms
71,128 KB
testcase_13 AC 62 ms
71,356 KB
testcase_14 AC 62 ms
71,404 KB
testcase_15 AC 87 ms
84,032 KB
testcase_16 AC 103 ms
91,496 KB
testcase_17 AC 117 ms
105,084 KB
testcase_18 AC 116 ms
105,244 KB
testcase_19 AC 117 ms
105,324 KB
testcase_20 AC 124 ms
105,528 KB
testcase_21 AC 119 ms
104,984 KB
testcase_22 AC 118 ms
104,960 KB
testcase_23 AC 105 ms
96,272 KB
testcase_24 AC 107 ms
96,056 KB
testcase_25 AC 95 ms
91,420 KB
testcase_26 AC 98 ms
93,820 KB
testcase_27 AC 85 ms
82,816 KB
testcase_28 AC 120 ms
102,100 KB
testcase_29 AC 120 ms
102,016 KB
testcase_30 AC 94 ms
86,732 KB
testcase_31 AC 105 ms
93,840 KB
testcase_32 AC 128 ms
105,340 KB
testcase_33 AC 109 ms
96,036 KB
testcase_34 AC 105 ms
93,720 KB
testcase_35 AC 88 ms
84,140 KB
testcase_36 AC 88 ms
83,308 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