結果

問題 No.823 Many Shifts Easy
ユーザー ttrttr
提出日時 2020-02-26 21:45:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 659 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-04-21 16:34:54
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 36 ms
10,752 KB
testcase_03 AC 617 ms
18,432 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 398 ms
15,616 KB
testcase_06 AC 659 ms
18,560 KB
testcase_07 AC 31 ms
10,624 KB
testcase_08 AC 644 ms
18,432 KB
testcase_09 AC 107 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mod = 10**9+7

g1 = [1]*(N+1)
g2 = [1]*(N+1)
for i in range(1, N+1):
    g1[i] = (g1[i-1]*i)%mod
    g2[i] = (g2[i-1]*pow(i, mod-2, mod))%mod

def cmb(n, r, mod):
    if n < r or r < 0:
        return 0
    return (g1[n]*g2[n-r]*g2[r])%mod

ans = 0
if N == K:
    for i in range(1, N):
        ans += i * cmb(N, 2, mod) * g1[N-2] % mod
        ans %= mod
else:
    for i in range(1, N):
        ans += i * (g1[N-1]*g2[N-1-K] + cmb(K, 2, mod)*g1[N-2]*g2[N-K]) % mod
        ans %= mod
    ans += N * g1[N-1] * g2[N-1-K] % mod
    ans %= mod

print(ans)
0