結果

問題 No.2369 Some Products
ユーザー gew1fw
提出日時 2025-06-12 18:56:29
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 978 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 82,632 KB
実行使用メモリ 53,168 KB
最終ジャッジ日時 2025-06-12 18:56:34
合計ジャッジ時間 4,509 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    P = list(map(int, input[ptr:ptr+N]))
    ptr += N
    Q = int(input[ptr])
    ptr += 1
    queries = []
    for _ in range(Q):
        A = int(input[ptr])
        B = int(input[ptr+1])
        K = int(input[ptr+2])
        queries.append((A-1, B-1, K))  # Convert to 0-based indices
        ptr +=3
    
    # Precompute modulo for P
    P_mod = [x % MOD for x in P]
    
    for A, B, K in queries:
        L = B - A + 1
        if K > L:
            print(0)
            continue
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(A, B + 1):
            x = P_mod[i]
            # Iterate from current_max down to 1
            current_max = min(K, i - A + 1)
            for k in range(current_max, 0, -1):
                dp[k] = (dp[k] + dp[k-1] * x) % MOD
        print(dp[K] % MOD)

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