結果

問題 No.2369 Some Products
ユーザー gew1fw
提出日時 2025-06-12 14:33:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 812 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,748 KB
実行使用メモリ 85,940 KB
最終ジャッジ日時 2025-06-12 14:33:39
合計ジャッジ時間 4,601 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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])
        ptr +=3
        queries.append( (A, B, K) )
    
    for A, B, K in queries:
        sub = P[A-1 : B]
        M = len(sub)
        if K > M:
            print(0)
            continue
        dp = [0]*(K+1)
        dp[0] = 1
        for s in sub:
            s_mod = s % MOD
            for j in range( min(K, len(dp)-1), 0, -1 ):
                dp[j] = (dp[j] + s_mod * dp[j-1]) % MOD
        print(dp[K] % MOD)
    
if __name__ == "__main__":
    main()
0