結果

問題 No.823 Many Shifts Easy
ユーザー rlangevinrlangevin
提出日時 2023-03-09 12:24:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 81,892 KB
実行使用メモリ 83,812 KB
最終ジャッジ日時 2023-10-18 06:14:12
合計ジャッジ時間 2,431 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
62,820 KB
testcase_01 AC 48 ms
62,820 KB
testcase_02 AC 54 ms
65,060 KB
testcase_03 AC 146 ms
82,228 KB
testcase_04 AC 49 ms
62,820 KB
testcase_05 AC 118 ms
80,908 KB
testcase_06 AC 171 ms
81,172 KB
testcase_07 AC 49 ms
62,820 KB
testcase_08 AC 171 ms
83,812 KB
testcase_09 AC 72 ms
75,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7

n = 205050

fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod


N, K = map(int, input().split())
ans = comb(N - 1, K) * fact[K] * N
for i in range(1, N):
    ans += comb(N - 1, K) * fact[K] * i
    ans += comb(N - 2, K - 2) * fact[K] * pow(2, mod - 2, mod) * i
    ans %= mod
print(ans)
0