結果

問題 No.1102 Remnants
ユーザー 👑 tamatotamato
提出日時 2020-07-03 21:43:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 171,120 KB
最終ジャッジ日時 2023-10-17 00:06:38
合計ジャッジ時間 4,422 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
64,520 KB
testcase_01 AC 51 ms
64,520 KB
testcase_02 AC 52 ms
64,520 KB
testcase_03 AC 52 ms
64,520 KB
testcase_04 AC 52 ms
64,520 KB
testcase_05 AC 147 ms
143,252 KB
testcase_06 AC 72 ms
83,396 KB
testcase_07 AC 169 ms
171,120 KB
testcase_08 AC 59 ms
69,308 KB
testcase_09 AC 62 ms
72,736 KB
testcase_10 AC 58 ms
67,260 KB
testcase_11 AC 60 ms
69,956 KB
testcase_12 AC 63 ms
73,044 KB
testcase_13 AC 62 ms
73,044 KB
testcase_14 AC 107 ms
117,168 KB
testcase_15 AC 96 ms
106,588 KB
testcase_16 AC 149 ms
135,568 KB
testcase_17 AC 146 ms
125,740 KB
testcase_18 AC 144 ms
136,808 KB
testcase_19 AC 89 ms
103,456 KB
testcase_20 AC 64 ms
77,768 KB
testcase_21 AC 121 ms
130,388 KB
testcase_22 AC 132 ms
125,304 KB
testcase_23 AC 121 ms
124,844 KB
testcase_24 AC 99 ms
111,912 KB
testcase_25 AC 151 ms
140,888 KB
testcase_26 AC 62 ms
73,392 KB
testcase_27 AC 81 ms
93,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    # comb init
    # mod = 1000000007
    nmax = 2 * 10 ** 5 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

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

    facK = {K+1: K+1}
    for i in range(2, N*2):
        facK[K+i] = (facK[K+i-1] * (K+i))%mod

    ans = 0
    for i, a in enumerate(A):
        if i == 0:
            l = 1
        else:
            l = (facK[i+1 + K - 1] * finv[i])%mod
        if i == N-1:
            r = 1
        else:
            r = (facK[N-i + K - 1] * finv[N-i-1])%mod
        ans = (ans + ((a * l)%mod * r)%mod)%mod
    print(ans)


if __name__ == '__main__':
    main()
0