結果

問題 No.1081 和の和
ユーザー toyuzukotoyuzuko
提出日時 2020-06-22 17:59:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 7,992 KB
最終ジャッジ日時 2023-09-16 19:17:27
合計ジャッジ時間 875 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

MOD = 1000000007

class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def comb(self, m, k):
        if m < k: return 0
        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

N = int(input())
A = list(map(int, input().split()))

f = Factorial(N, MOD)
res = 0

for i in range(N):
    res += f.comb(N - 1, i) * A[i]
    res %= MOD

print(res)
0