結果

問題 No.1239 Multiplication -2
ユーザー zkouzkou
提出日時 2020-09-25 23:00:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,176 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 10,740 KB
実行使用メモリ 21,216 KB
最終ジャッジ日時 2023-09-10 16:07:48
合計ジャッジ時間 16,616 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,776 KB
testcase_01 AC 15 ms
7,756 KB
testcase_02 AC 16 ms
7,736 KB
testcase_03 AC 24 ms
8,172 KB
testcase_04 AC 23 ms
8,240 KB
testcase_05 AC 25 ms
8,348 KB
testcase_06 AC 19 ms
7,768 KB
testcase_07 AC 18 ms
7,892 KB
testcase_08 AC 16 ms
7,756 KB
testcase_09 AC 16 ms
7,756 KB
testcase_10 AC 16 ms
7,812 KB
testcase_11 AC 16 ms
7,828 KB
testcase_12 AC 16 ms
7,812 KB
testcase_13 AC 15 ms
7,768 KB
testcase_14 AC 16 ms
7,756 KB
testcase_15 AC 292 ms
11,000 KB
testcase_16 AC 490 ms
13,104 KB
testcase_17 AC 1,176 ms
12,084 KB
testcase_18 AC 1,009 ms
14,540 KB
testcase_19 AC 872 ms
15,360 KB
testcase_20 AC 1,063 ms
21,216 KB
testcase_21 AC 822 ms
11,520 KB
testcase_22 AC 774 ms
11,424 KB
testcase_23 AC 651 ms
19,376 KB
testcase_24 AC 623 ms
17,528 KB
testcase_25 AC 431 ms
10,304 KB
testcase_26 AC 549 ms
18,092 KB
testcase_27 AC 260 ms
10,728 KB
testcase_28 AC 799 ms
16,464 KB
testcase_29 AC 863 ms
17,372 KB
testcase_30 AC 383 ms
11,760 KB
testcase_31 AC 562 ms
13,632 KB
testcase_32 AC 919 ms
17,704 KB
testcase_33 AC 651 ms
14,408 KB
testcase_34 AC 601 ms
14,128 KB
testcase_35 AC 302 ms
11,256 KB
testcase_36 AC 276 ms
10,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
As = list(map(int, input().split()))

MOD = 998244353

half = pow(2, MOD - 2, MOD)

alphas = [0] * 5
dp = [0] * (N + 1)
dpsum = 0
prod = 1
for i, A in enumerate(As):
    prod *= A
    if not (-2 <= prod <= 2):
        prod = 0
    if prod == -2:
        dp[i + 1] += pow(2, MOD - 2 - i, MOD)
    alphas[1] += 1
    new_alphas = [0] * 5
    for j in range(-2, 3):
        index = j * A
        if not (-2 <= index <= 2):
            index = 0
        new_alphas[index] += alphas[j] * half
        new_alphas[index] %= MOD
    alphas = new_alphas
    dp[i + 1] += (dpsum + alphas[-2]) % MOD
    dp[i + 1] %= MOD
    dpsum += dp[i + 1]
    dpsum = dpsum * half % MOD
    
# print(dp)

print(dp[-1])
0