結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー tamatotamato
提出日時 2020-05-29 21:45:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 594 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 72,156 KB
最終ジャッジ日時 2024-04-23 21:08:14
合計ジャッジ時間 5,197 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,928 KB
testcase_01 AC 39 ms
53,372 KB
testcase_02 AC 39 ms
52,832 KB
testcase_03 AC 36 ms
53,472 KB
testcase_04 AC 35 ms
52,504 KB
testcase_05 AC 35 ms
52,760 KB
testcase_06 AC 34 ms
53,252 KB
testcase_07 AC 35 ms
53,608 KB
testcase_08 AC 239 ms
70,112 KB
testcase_09 AC 43 ms
62,080 KB
testcase_10 AC 575 ms
71,624 KB
testcase_11 AC 158 ms
68,616 KB
testcase_12 AC 132 ms
68,480 KB
testcase_13 AC 162 ms
68,484 KB
testcase_14 AC 189 ms
68,796 KB
testcase_15 AC 382 ms
71,020 KB
testcase_16 AC 99 ms
67,620 KB
testcase_17 AC 114 ms
67,764 KB
testcase_18 AC 375 ms
70,648 KB
testcase_19 AC 163 ms
69,196 KB
testcase_20 AC 46 ms
61,412 KB
testcase_21 AC 283 ms
69,612 KB
testcase_22 AC 50 ms
62,600 KB
testcase_23 AC 39 ms
52,400 KB
testcase_24 AC 38 ms
53,512 KB
testcase_25 AC 594 ms
72,156 KB
testcase_26 AC 261 ms
71,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
eps = 10**-9


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

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

    dp = [[0] * (N+1) for _ in range(2)]
    dp[0][0] = 1
    for i in range(N):
        a = A[i]
        for j in range(N+1):
            dp[(i+1)%2][j] = 0
        for j in range(N+1):
            if dp[i%2][j] == 0:
                continue
            dp[(i+1)%2][j] = (dp[(i+1)%2][j] + dp[i%2][j] * (a - 1))%mod
            if j+1 <= N:
                dp[(i+1)%2][j+1] = (dp[(i+1)%2][j+1] + dp[i%2][j])%mod
    for b in B:
        print(dp[N%2][b])


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