結果

問題 No.1145 Sums of Powers
ユーザー gew1fw
提出日時 2025-06-12 16:35:01
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 911 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 849,072 KB
最終ジャッジ日時 2025-06-12 16:35:04
合計ジャッジ時間 3,035 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 MLE * 1 -- * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    idx = 0
    N = int(data[idx])
    idx += 1
    M = int(data[idx])
    idx += 1
    A = list(map(int, data[idx:idx + N]))
    idx += N

    # Precompute powers for each A_i up to M
    # Initialize a list of lists, where each sublist is the powers of A_i
    powers = []
    for a in A:
        if a == 0:
            powers.append([0] * (M + 1))
            continue
        pows = [1] * (M + 1)
        for k in range(1, M + 1):
            pows[k] = (pows[k - 1] * a) % MOD
        powers.append(pows)
    
    # Compute S_K for each K from 1 to M
    S = [0] * (M + 1)
    for k in range(1, M + 1):
        s = 0
        for i in range(N):
            s = (s + powers[i][k]) % MOD
        S[k] = s
    
    # Output S_1 to S_M
    print(' '.join(map(str, S[1:M+1])))

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