結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー Salmonize
提出日時 2020-05-29 21:48:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,041 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 71,088 KB
最終ジャッジ日時 2024-11-06 03:44:24
合計ジャッジ時間 7,795 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


def solve():
    mod = 998244353
    n, q = nm()
    a = nl()
    b = nl()
    dp = [[0]*(n+2) for i in range(2)]
    dp[0][0] = 1
    for i in range(n):
        v = i & 1
        for j in range(n+1):
            if dp[v][j]:
                dp[v^1][j+1] = (dp[v^1][j+1] + dp[v][j]) % mod
                dp[v^1][j] = (dp[v^1][j] + (a[i] - 1) * dp[v][j]) % mod
            dp[v][j] = 0
        # print(dp[v^1])
    for x in b:
        print(dp[n&1][x])
    return

solve()
0