結果

問題 No.1081 和の和
ユーザー zyxwzyxw
提出日時 2021-02-04 10:41:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 76,872 KB
最終ジャッジ日時 2023-09-13 05:39:40
合計ジャッジ時間 3,007 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
72,264 KB
testcase_01 AC 105 ms
72,244 KB
testcase_02 AC 105 ms
72,344 KB
testcase_03 AC 106 ms
72,248 KB
testcase_04 AC 111 ms
76,848 KB
testcase_05 AC 106 ms
72,576 KB
testcase_06 AC 109 ms
76,676 KB
testcase_07 AC 114 ms
76,804 KB
testcase_08 AC 115 ms
76,796 KB
testcase_09 AC 112 ms
76,860 KB
testcase_10 AC 115 ms
76,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import reduce
mod = 10 ** 9 + 7
def cmb(n,r,mod):
    numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
    denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
    return numerator * pow(denominator, mod - 2, mod) % mod
N=int(input())
nCr=[]
for i in range(N-2):
    nCr.append(cmb(N-1,i+1,mod))
A=list(map(int,input().split()))
ans=A[0]+A[N-1]
for i in range(N-2):
    ans+=nCr[i]*A[i+1]
    ans%=mod
print(ans)
0