結果

問題 No.1081 和の和
ユーザー uni_pythonuni_python
提出日時 2020-06-19 21:38:31
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 87,484 KB
実行使用メモリ 71,316 KB
最終ジャッジ日時 2023-09-16 13:40:39
合計ジャッジ時間 1,901 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,220 KB
testcase_01 AC 69 ms
71,068 KB
testcase_02 AC 70 ms
70,808 KB
testcase_03 AC 67 ms
71,172 KB
testcase_04 AC 68 ms
71,072 KB
testcase_05 AC 70 ms
71,036 KB
testcase_06 AC 71 ms
71,184 KB
testcase_07 AC 69 ms
71,184 KB
testcase_08 AC 70 ms
71,316 KB
testcase_09 AC 71 ms
71,172 KB
testcase_10 AC 69 ms
71,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

def main():
    mod=10**9+7
    N=I()
    A=LI()
    ans=0
    
    n=N+3
    
    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return (fact[n] * factinv[r] * factinv[n-r])%mod

    fact=[1,1]
    factinv=[1,1]
    inv=[0,1]
    
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
    
    
    for i in range(1,N-1):
        ans=(ans+A[i]*cmb(N-1,i,mod))%mod
    ans+=A[0]+A[-1]
    
    print(ans%mod)
    
    

        
    
    
    


main()

0