結果
問題 |
No.2369 Some Products
|
ユーザー |
![]() |
提出日時 | 2025-03-31 17:32:17 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 913 bytes |
コンパイル時間 | 162 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 54,008 KB |
最終ジャッジ日時 | 2025-03-31 17:33:13 |
合計ジャッジ時間 | 4,573 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 1 TLE * 1 -- * 12 |
ソースコード
import sys MOD = 998244353 def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 # Preprocess P with mod P = [int(x) % MOD for x in input[ptr:ptr + N]] ptr += N Q = int(input[ptr]) ptr += 1 queries = [] for _ in range(Q): A = int(input[ptr]) - 1 B = int(input[ptr+1]) - 1 K = int(input[ptr+2]) queries.append((A, B, K)) ptr += 3 for A, B, K in queries: L = B - A + 1 if K > L: print(0) continue # Initialize DP array dp = [0] * (K + 1) dp[0] = 1 cnt = 0 for i in range(A, B + 1): cnt += 1 p = P[i] maxk = min(K, cnt) for k in range(maxk, 0, -1): dp[k] = (dp[k] + dp[k-1] * p) % MOD print(dp[K] % MOD) if __name__ == "__main__": main()