結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー nephrologistnephrologist
提出日時 2020-05-29 22:16:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 828 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 73,384 KB
最終ジャッジ日時 2024-04-23 22:59:40
合計ジャッジ時間 6,872 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,800 KB
testcase_01 AC 33 ms
54,076 KB
testcase_02 AC 32 ms
52,704 KB
testcase_03 AC 33 ms
53,024 KB
testcase_04 AC 35 ms
53,208 KB
testcase_05 AC 33 ms
52,936 KB
testcase_06 AC 35 ms
52,724 KB
testcase_07 AC 33 ms
53,428 KB
testcase_08 AC 337 ms
71,596 KB
testcase_09 AC 42 ms
60,996 KB
testcase_10 AC 785 ms
72,296 KB
testcase_11 AC 213 ms
70,508 KB
testcase_12 AC 175 ms
70,884 KB
testcase_13 AC 220 ms
71,304 KB
testcase_14 AC 225 ms
71,328 KB
testcase_15 AC 552 ms
71,732 KB
testcase_16 AC 122 ms
70,860 KB
testcase_17 AC 139 ms
70,848 KB
testcase_18 AC 505 ms
72,388 KB
testcase_19 AC 203 ms
71,580 KB
testcase_20 AC 42 ms
61,844 KB
testcase_21 AC 406 ms
71,736 KB
testcase_22 AC 42 ms
60,804 KB
testcase_23 AC 34 ms
53,488 KB
testcase_24 AC 33 ms
52,208 KB
testcase_25 AC 812 ms
73,384 KB
testcase_26 AC 828 ms
72,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
A = list(map(int, input().split()))

mod = 998244353
dp = [[0] * (n + 1) for _ in range(2)]
dp[0][0] = 1
now = 0
nxt = 1
for i in range(n):
    now = i % 2
    nxt = (i + 1) % 2
    for j in range(n + 1):
        dp[nxt][j] = 0
    for j in range(n + 1):
        nj = j
        dp[nxt][nj] += dp[now][j] * (A[i] - 1)
        dp[nxt][nj] %= mod
        nj = j + 1
        if nj <= n:
            dp[nxt][nj] += dp[now][j]
            dp[nxt][nj] %= mod


B = map(int, input().split())
for t in B:
    print(dp[nxt][t] % mod)
0