結果

問題 No.1239 Multiplication -2
ユーザー りあんりあん
提出日時 2020-09-03 22:06:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 732 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 21,400 KB
最終ジャッジ日時 2023-08-15 19:22:05
合計ジャッジ時間 13,694 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,844 KB
testcase_01 AC 15 ms
7,756 KB
testcase_02 AC 15 ms
7,856 KB
testcase_03 AC 22 ms
7,856 KB
testcase_04 AC 22 ms
7,804 KB
testcase_05 AC 23 ms
8,244 KB
testcase_06 AC 17 ms
7,884 KB
testcase_07 AC 18 ms
7,848 KB
testcase_08 AC 16 ms
7,756 KB
testcase_09 AC 15 ms
7,756 KB
testcase_10 AC 15 ms
7,972 KB
testcase_11 AC 15 ms
7,964 KB
testcase_12 AC 15 ms
7,888 KB
testcase_13 AC 16 ms
7,816 KB
testcase_14 AC 15 ms
7,852 KB
testcase_15 AC 246 ms
10,804 KB
testcase_16 AC 408 ms
12,528 KB
testcase_17 AC 719 ms
11,364 KB
testcase_18 AC 730 ms
11,400 KB
testcase_19 AC 721 ms
13,196 KB
testcase_20 AC 732 ms
21,400 KB
testcase_21 AC 706 ms
11,448 KB
testcase_22 AC 673 ms
11,340 KB
testcase_23 AC 540 ms
19,604 KB
testcase_24 AC 500 ms
17,568 KB
testcase_25 AC 422 ms
10,236 KB
testcase_26 AC 482 ms
18,116 KB
testcase_27 AC 207 ms
10,752 KB
testcase_28 AC 649 ms
16,636 KB
testcase_29 AC 704 ms
17,536 KB
testcase_30 AC 304 ms
11,792 KB
testcase_31 AC 442 ms
13,696 KB
testcase_32 AC 731 ms
17,784 KB
testcase_33 AC 532 ms
14,588 KB
testcase_34 AC 489 ms
13,884 KB
testcase_35 AC 250 ms
11,308 KB
testcase_36 AC 221 ms
11,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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