結果

問題 No.1239 Multiplication -2
ユーザー tamatotamato
提出日時 2020-09-25 22:18:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 110,324 KB
最終ジャッジ日時 2023-09-10 15:32:44
合計ジャッジ時間 6,396 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,780 KB
testcase_01 AC 73 ms
71,744 KB
testcase_02 AC 74 ms
71,276 KB
testcase_03 AC 93 ms
76,876 KB
testcase_04 AC 94 ms
76,948 KB
testcase_05 AC 93 ms
76,800 KB
testcase_06 AC 84 ms
76,496 KB
testcase_07 AC 85 ms
76,340 KB
testcase_08 AC 74 ms
71,680 KB
testcase_09 AC 75 ms
71,784 KB
testcase_10 AC 73 ms
71,780 KB
testcase_11 AC 75 ms
71,524 KB
testcase_12 AC 75 ms
71,600 KB
testcase_13 AC 74 ms
71,792 KB
testcase_14 AC 73 ms
71,576 KB
testcase_15 AC 123 ms
92,148 KB
testcase_16 AC 144 ms
99,780 KB
testcase_17 AC 178 ms
110,236 KB
testcase_18 AC 172 ms
110,088 KB
testcase_19 AC 184 ms
110,308 KB
testcase_20 AC 179 ms
109,736 KB
testcase_21 AC 174 ms
110,108 KB
testcase_22 AC 175 ms
110,324 KB
testcase_23 AC 150 ms
103,160 KB
testcase_24 AC 149 ms
103,168 KB
testcase_25 AC 130 ms
99,536 KB
testcase_26 AC 139 ms
101,076 KB
testcase_27 AC 118 ms
89,840 KB
testcase_28 AC 175 ms
107,256 KB
testcase_29 AC 180 ms
107,180 KB
testcase_30 AC 133 ms
96,192 KB
testcase_31 AC 151 ms
101,464 KB
testcase_32 AC 191 ms
110,036 KB
testcase_33 AC 159 ms
102,956 KB
testcase_34 AC 155 ms
101,392 KB
testcase_35 AC 123 ms
92,052 KB
testcase_36 AC 122 ms
90,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    half = pow(2, mod-2, mod)
    dp = [[0] * 5 for _ in range(N)]
    dp[0][1] = 1
    ans = 0
    for i, a in enumerate(A[:-1]):
        dp[i+1][1] = half
        for j in range(-2, 3):
            ja = j * a
            if not -2 <= ja <= 2:
                ja = 0
            dp[i+1][ja] = (dp[i+1][ja] + dp[i][j] * half)%mod
            if ja == -2:
                ans = (ans + dp[i][j] * half)%mod
    for j in range(-2, 3):
        if j * A[-1] == -2:
            ans = (ans + dp[-1][j])%mod
    print(ans)


if __name__ == '__main__':
    main()
0