結果

問題 No.1239 Multiplication -2
ユーザー KudeKude
提出日時 2020-09-25 22:29:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 86,480 KB
実行使用メモリ 105,092 KB
最終ジャッジ日時 2023-09-10 15:48:49
合計ジャッジ時間 8,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,452 KB
testcase_01 AC 72 ms
71,156 KB
testcase_02 AC 74 ms
71,452 KB
testcase_03 AC 91 ms
76,596 KB
testcase_04 AC 92 ms
76,412 KB
testcase_05 AC 100 ms
77,204 KB
testcase_06 AC 75 ms
71,012 KB
testcase_07 AC 76 ms
71,268 KB
testcase_08 AC 74 ms
71,408 KB
testcase_09 AC 73 ms
71,148 KB
testcase_10 AC 74 ms
71,404 KB
testcase_11 AC 72 ms
71,196 KB
testcase_12 AC 73 ms
71,208 KB
testcase_13 AC 74 ms
71,160 KB
testcase_14 AC 74 ms
70,840 KB
testcase_15 AC 182 ms
84,156 KB
testcase_16 AC 225 ms
91,516 KB
testcase_17 AC 315 ms
104,708 KB
testcase_18 AC 305 ms
104,508 KB
testcase_19 AC 324 ms
104,932 KB
testcase_20 AC 339 ms
105,092 KB
testcase_21 AC 298 ms
104,544 KB
testcase_22 AC 302 ms
104,876 KB
testcase_23 AC 238 ms
96,360 KB
testcase_24 AC 238 ms
96,432 KB
testcase_25 AC 193 ms
91,088 KB
testcase_26 AC 204 ms
93,692 KB
testcase_27 AC 193 ms
82,948 KB
testcase_28 AC 293 ms
101,608 KB
testcase_29 AC 308 ms
101,660 KB
testcase_30 AC 189 ms
86,504 KB
testcase_31 AC 241 ms
93,604 KB
testcase_32 AC 323 ms
104,972 KB
testcase_33 AC 265 ms
96,084 KB
testcase_34 AC 244 ms
94,016 KB
testcase_35 AC 172 ms
84,172 KB
testcase_36 AC 163 ms
82,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
n = int(input())
a = list(map(int, input().split()))
dp = [[1, 0], [0, 0]] # [abs is 2][sig is neg]
ans = 0
for z, x in enumerate(a):
    ndp = [[0, 0], [0, 0]]
    if x == 2:
        ndp[1][0] = dp[0][0]
        ndp[1][1] = dp[0][1]
    elif x == -2:
        ndp[1][0] = dp[0][1]
        ndp[1][1] = dp[0][0]
    elif x == 1:
        for i in range(2):
            for j in range(2):
                ndp[i][j] = dp[i][j]
    elif x == -1:
        for i in range(2):
            for j in range(2):
                ndp[i][j] = dp[i][1-j]
    ans = (ans + ndp[1][1] * pow(2, max(0, n - 2 - z), MOD)) % MOD
    ndp[0][0] += pow(2, z, MOD)
    ndp[0][0] %= MOD
    dp = ndp
q = pow(2, n-1, MOD)
print(ans * pow(q, MOD-2, MOD) % MOD)
0