結果

問題 No.797 Noelちゃんとピラミッド
ユーザー lam6er
提出日時 2025-03-20 20:42:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 758 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 82,812 KB
実行使用メモリ 90,644 KB
最終ジャッジ日時 2025-03-20 20:42:52
合計ジャッジ時間 6,701 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9 + 7
max_n = 10**5 + 5  # Precompute up to 1e5 to cover all possibilities

# Precompute factorial and inverse factorial arrays
fact = [1] * (max_n)
for i in range(1, max_n):
    fact[i] = fact[i-1] * i % MOD

inv_fact = [1] * (max_n)
inv_fact[max_n - 1] = pow(fact[max_n - 1], MOD - 2, MOD)
for i in range(max_n - 2, -1, -1):
    inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    return fact[n] * inv_fact[k] % MOD * inv_fact[n - k] % MOD

n = int(input())
a = list(map(int, input().split()))

if n == 1:
    print(a[0] % MOD)
else:
    result = 0
    m = n - 1
    for i in range(n):
        c = comb(m, i)
        ai = a[i] % MOD
        result = (result + ai * c) % MOD
    print(result)
0