結果
| 問題 | 
                            No.2005 Sum of Power Sums
                             | 
                    
| コンテスト | |
| ユーザー | 
                             lam6er
                         | 
                    
| 提出日時 | 2025-04-15 23:58:24 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,620 bytes | 
| コンパイル時間 | 317 ms | 
| コンパイル使用メモリ | 82,416 KB | 
| 実行使用メモリ | 307,456 KB | 
| 最終ジャッジ日時 | 2025-04-16 00:00:02 | 
| 合計ジャッジ時間 | 10,959 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 TLE * 1 -- * 5 | 
ソースコード
MOD = 998244353
# Precompute Stirling numbers of the second kind up to 5000
max_k = 5000
stirling = [[0] * (max_k + 1) for _ in range(max_k + 1)]
stirling[0][0] = 1
for k in range(1, max_k + 1):
    for m in range(1, k + 1):
        stirling[k][m] = (m * stirling[k-1][m] + stirling[k-1][m-1]) % MOD
# Precompute factorials and inverse factorials up to 205000
max_fact = 205000
fact = [1] * (max_fact + 1)
for i in range(1, max_fact + 1):
    fact[i] = fact[i-1] * i % MOD
inv_fact = [1] * (max_fact + 1)
inv_fact[max_fact] = pow(fact[max_fact], MOD-2, MOD)
for i in range(max_fact - 1, -1, -1):
    inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
# Read input
n, M = map(int, input().split())
K_list = list(map(int, input().split()))
max_term = n + max(K_list) if K_list else 0  # Handle empty K_list case
term = [0] * (max_term + 2)  # term[1..max_term]
M_mod = M % MOD
for i in range(1, max_term + 1):
    val = (M_mod + (n - i + 1)) % MOD
    if val < 0:
        val += MOD
    term[i] = val
# Compute prefix product
prefix = [1] * (max_term + 2)
for i in range(1, max_term + 1):
    prefix[i] = prefix[i-1] * term[i] % MOD
total = 0
for K in K_list:
    current_sum = 0
    for m in range(0, K + 1):
        s = stirling[K][m]
        if s == 0:
            continue
        nm = n + m
        if nm > max_term:
            continue  # This should not happen as max_term is set correctly
        c = prefix[nm] * inv_fact[nm] % MOD
        term_val = s * fact[m] % MOD
        term_val = term_val * c % MOD
        current_sum = (current_sum + term_val) % MOD
    total = (total + current_sum) % MOD
print(total)
            
            
            
        
            
lam6er