結果

問題 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  
実行時間 629 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 18,304 KB
最終ジャッジ日時 2024-10-13 15:31:02
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 32 ms
10,624 KB
testcase_02 AC 36 ms
10,752 KB
testcase_03 AC 584 ms
18,304 KB
testcase_04 AC 28 ms
10,496 KB
testcase_05 AC 373 ms
15,488 KB
testcase_06 AC 629 ms
18,304 KB
testcase_07 AC 30 ms
10,496 KB
testcase_08 AC 611 ms
18,176 KB
testcase_09 AC 103 ms
11,392 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