結果

問題 No.1239 Multiplication -2
ユーザー ibyiby
提出日時 2020-11-27 01:47:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,160 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 11,060 KB
実行使用メモリ 61,536 KB
最終ジャッジ日時 2023-10-01 03:47:29
合計ジャッジ時間 21,763 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,312 KB
testcase_01 AC 16 ms
8,196 KB
testcase_02 AC 16 ms
8,352 KB
testcase_03 AC 24 ms
8,524 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 19 ms
8,052 KB
testcase_07 AC 19 ms
8,136 KB
testcase_08 AC 16 ms
8,240 KB
testcase_09 AC 16 ms
8,252 KB
testcase_10 AC 15 ms
8,344 KB
testcase_11 AC 15 ms
8,288 KB
testcase_12 AC 15 ms
8,224 KB
testcase_13 AC 16 ms
8,160 KB
testcase_14 AC 16 ms
8,208 KB
testcase_15 AC 349 ms
24,376 KB
testcase_16 AC 587 ms
35,328 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1,268 ms
61,152 KB
testcase_20 WA -
testcase_21 AC 1,235 ms
60,420 KB
testcase_22 AC 1,094 ms
57,040 KB
testcase_23 AC 893 ms
45,352 KB
testcase_24 AC 795 ms
43,000 KB
testcase_25 AC 399 ms
35,192 KB
testcase_26 AC 765 ms
41,156 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1,203 ms
57,500 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 1,241 ms
60,548 KB
testcase_33 AC 852 ms
44,712 KB
testcase_34 AC 787 ms
41,912 KB
testcase_35 WA -
testcase_36 AC 344 ms
23,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
n = int(input())
a = list(map(int, input().split()))
numerator = 0
denominator = pow(2, n - 1, MOD)
dp = [{0: 0, -1: 0, 1: 0, 2: 0, -2: 0} for i in range(n + 1)]
for i, v in enumerate(a):
    if v == 1:
        dp[i + 1][1] = (pow(2, i - 1, MOD) + dp[i][1]) % MOD
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][-1] = dp[i][-1]
        dp[i + 1][-2] = dp[i][-2]
        continue
    elif v == 2:
        dp[i + 1][2] = (dp[i][1] + pow(2, max(i - 1, 0), MOD)) % MOD
        dp[i + 1][-2] = dp[i][-1]
        continue
    elif v == -1:
        dp[i + 1][1] = dp[i][-1]
        dp[i + 1][-1] = (pow(2, i - 1, MOD) + dp[i][1]) % MOD
        dp[i + 1][2] = dp[i][-2]
        dp[i + 1][-2] = dp[i][2]
        continue
    elif v == -2:
        dp[i + 1][2] = dp[i][-1]
        dp[i + 1][-2] = (dp[i][1] + pow(2, max(i - 1, 0), MOD)) % MOD
        continue
    else:
        dp[i + 1][0] = 1

for i in range(n + 1):
    if i != n:
        numerator += dp[i][-2] * pow(2, n - i - 1, MOD)
    else:
        numerator += dp[i][-2]
    numerator %= MOD

#print(numerator, denominator)
ans = (numerator * pow(denominator, MOD - 2, MOD)) % MOD
print(ans)
0