結果
| 問題 |
No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 15:57:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 185 ms / 2,000 ms |
| コード長 | 790 bytes |
| コンパイル時間 | 360 ms |
| コンパイル使用メモリ | 82,404 KB |
| 実行使用メモリ | 77,744 KB |
| 最終ジャッジ日時 | 2025-03-20 15:57:31 |
| 合計ジャッジ時間 | 3,997 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
MOD = 998244353
def main():
import sys
input = sys.stdin.read().split()
ptr = 0
N, Q = int(input[ptr]), int(input[ptr + 1])
ptr += 2
A = list(map(int, input[ptr:ptr + N]))
ptr += N
B = list(map(int, input[ptr:ptr + Q]))
dp = [0] * (N + 1)
dp[0] = 1
current_max = 0
for a in A:
tmp = [0] * (N + 1)
for j in range(current_max + 1):
# Case where we don't choose color 1 from this box
tmp[j] = (tmp[j] + dp[j] * (a - 1)) % MOD
# Case where we choose color 1 from this box
if j + 1 <= N:
tmp[j + 1] = (tmp[j + 1] + dp[j]) % MOD
dp = tmp
current_max += 1
for b in B:
print(dp[b] % MOD)
if __name__ == '__main__':
main()
lam6er