結果

問題 No.1081 和の和
ユーザー 👑 rin204rin204
提出日時 2020-06-25 04:11:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 7,924 KB
最終ジャッジ日時 2023-09-16 21:34:27
合計ジャッジ時間 1,276 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,780 KB
testcase_01 AC 16 ms
7,740 KB
testcase_02 AC 16 ms
7,880 KB
testcase_03 AC 16 ms
7,740 KB
testcase_04 AC 16 ms
7,800 KB
testcase_05 AC 16 ms
7,824 KB
testcase_06 AC 15 ms
7,856 KB
testcase_07 AC 16 ms
7,792 KB
testcase_08 AC 16 ms
7,820 KB
testcase_09 AC 16 ms
7,924 KB
testcase_10 AC 16 ms
7,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

MOD = 10 ** 9 + 7

fact = [0 for _ in range(n)]
invfact = [0 for _ in range(n)]
fact[0] = 1
for i in range(1, n):
    fact[i] = fact[i - 1] * i % MOD

invfact[n - 1] = pow(fact[n - 1], MOD - 2, MOD)

for i in range(n - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD
def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[k] * invfact[n - k] % MOD
        
ans = 0
for i, num in enumerate(alst):
    ans += nCk(n - 1, i) * num
    ans %= MOD
print(ans)
0