結果

問題 No.797 Noelちゃんとピラミッド
ユーザー ThetaTheta
提出日時 2024-03-29 13:45:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 105,180 KB
最終ジャッジ日時 2024-03-29 13:45:59
合計ジャッジ時間 10,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,600 KB
testcase_01 AC 44 ms
55,600 KB
testcase_02 AC 45 ms
55,600 KB
testcase_03 AC 155 ms
103,028 KB
testcase_04 AC 155 ms
103,032 KB
testcase_05 AC 153 ms
103,032 KB
testcase_06 AC 153 ms
103,032 KB
testcase_07 AC 182 ms
103,032 KB
testcase_08 AC 153 ms
103,028 KB
testcase_09 AC 154 ms
103,032 KB
testcase_10 AC 152 ms
103,028 KB
testcase_11 AC 154 ms
103,036 KB
testcase_12 AC 152 ms
103,024 KB
testcase_13 AC 152 ms
103,036 KB
testcase_14 AC 176 ms
103,032 KB
testcase_15 AC 152 ms
103,032 KB
testcase_16 AC 152 ms
103,024 KB
testcase_17 AC 152 ms
103,032 KB
testcase_18 AC 151 ms
103,024 KB
testcase_19 AC 151 ms
103,028 KB
testcase_20 AC 152 ms
103,028 KB
testcase_21 AC 154 ms
103,032 KB
testcase_22 AC 158 ms
103,036 KB
testcase_23 AC 136 ms
105,068 KB
testcase_24 AC 83 ms
81,612 KB
testcase_25 AC 110 ms
93,160 KB
testcase_26 AC 105 ms
91,588 KB
testcase_27 AC 151 ms
103,100 KB
testcase_28 AC 146 ms
103,084 KB
testcase_29 AC 79 ms
79,364 KB
testcase_30 AC 93 ms
81,548 KB
testcase_31 AC 138 ms
105,180 KB
testcase_32 AC 91 ms
83,672 KB
testcase_33 AC 107 ms
93,168 KB
testcase_34 AC 95 ms
87,404 KB
testcase_35 AC 151 ms
103,028 KB
testcase_36 AC 76 ms
78,752 KB
testcase_37 AC 145 ms
103,068 KB
testcase_38 AC 148 ms
103,160 KB
testcase_39 AC 115 ms
93,152 KB
testcase_40 AC 77 ms
78,756 KB
testcase_41 AC 80 ms
80,312 KB
testcase_42 AC 107 ms
91,564 KB
testcase_43 AC 46 ms
55,600 KB
testcase_44 AC 45 ms
55,600 KB
testcase_45 AC 44 ms
55,600 KB
testcase_46 AC 44 ms
55,600 KB
testcase_47 AC 43 ms
55,600 KB
testcase_48 AC 44 ms
55,600 KB
testcase_49 AC 44 ms
55,600 KB
testcase_50 AC 45 ms
55,600 KB
testcase_51 AC 44 ms
55,600 KB
testcase_52 AC 44 ms
55,600 KB
testcase_53 AC 44 ms
55,600 KB
testcase_54 AC 44 ms
55,600 KB
testcase_55 AC 43 ms
55,600 KB
testcase_56 AC 43 ms
55,600 KB
testcase_57 AC 45 ms
55,600 KB
testcase_58 AC 48 ms
55,600 KB
testcase_59 AC 45 ms
55,600 KB
testcase_60 AC 44 ms
55,600 KB
testcase_61 AC 44 ms
55,600 KB
testcase_62 AC 45 ms
55,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cache


def COMinit(upper: int,
            mod_: int) -> tuple[list[int],
                                list[int],
                                list[int]]:

    fac = [0 for _ in range(upper)]
    finv = [0 for _ in range(upper)]
    inv = [0 for _ in range(upper)]
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1

    for i in range(2, upper):
        fac[i] = (fac[i - 1] * i)
        fac[i] %= mod_
        inv[i] = mod_ - inv[mod_ % i] * (mod_ // i)
        inv[i] %= mod_
        finv[i] = finv[i - 1] * inv[i]
        finv[i] %= mod_

    return fac, finv, inv


def main():
    N = int(input())
    a = list(map(int, input().split()))
    MOD = int(1e9 + 7)

    fac, finv, inv = COMinit(N + 20, MOD)
    c_sum = 0

    @cache
    def com(n: int, k: int) -> int:
        if n < k:
            return 0
        if (n < 0 or k < 0):
            return 0

        return (fac[n] * finv[k] * finv[n - k]) % MOD
    for k in range(N):
        c_sum += com(N - 1, k) * a[k]
        c_sum %= MOD
    print(c_sum)


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