結果

問題 No.1259 スイッチ
ユーザー mkawa2mkawa2
提出日時 2021-12-05 00:26:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 630 ms / 2,000 ms
コード長 1,660 bytes
コンパイル時間 2,458 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 160,868 KB
最終ジャッジ日時 2023-09-21 13:08:40
合計ジャッジ時間 22,166 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
159,948 KB
testcase_01 AC 146 ms
159,916 KB
testcase_02 AC 144 ms
159,732 KB
testcase_03 AC 143 ms
159,956 KB
testcase_04 AC 145 ms
159,876 KB
testcase_05 AC 144 ms
160,148 KB
testcase_06 AC 144 ms
160,220 KB
testcase_07 AC 142 ms
160,100 KB
testcase_08 AC 142 ms
159,808 KB
testcase_09 AC 144 ms
159,920 KB
testcase_10 AC 428 ms
160,256 KB
testcase_11 AC 597 ms
160,268 KB
testcase_12 AC 416 ms
160,152 KB
testcase_13 AC 299 ms
160,080 KB
testcase_14 AC 366 ms
160,188 KB
testcase_15 AC 291 ms
159,784 KB
testcase_16 AC 511 ms
159,732 KB
testcase_17 AC 363 ms
160,868 KB
testcase_18 AC 568 ms
160,596 KB
testcase_19 AC 564 ms
160,276 KB
testcase_20 AC 430 ms
159,984 KB
testcase_21 AC 616 ms
160,456 KB
testcase_22 AC 276 ms
159,980 KB
testcase_23 AC 555 ms
159,976 KB
testcase_24 AC 454 ms
160,044 KB
testcase_25 AC 440 ms
160,108 KB
testcase_26 AC 615 ms
160,484 KB
testcase_27 AC 523 ms
159,784 KB
testcase_28 AC 444 ms
160,128 KB
testcase_29 AC 523 ms
160,140 KB
testcase_30 AC 150 ms
159,828 KB
testcase_31 AC 155 ms
159,736 KB
testcase_32 AC 145 ms
159,968 KB
testcase_33 AC 158 ms
160,360 KB
testcase_34 AC 152 ms
159,888 KB
testcase_35 AC 155 ms
160,184 KB
testcase_36 AC 156 ms
160,416 KB
testcase_37 AC 153 ms
159,692 KB
testcase_38 AC 154 ms
160,100 KB
testcase_39 AC 158 ms
160,204 KB
testcase_40 AC 158 ms
159,824 KB
testcase_41 AC 156 ms
159,736 KB
testcase_42 AC 158 ms
160,084 KB
testcase_43 AC 153 ms
159,960 KB
testcase_44 AC 159 ms
160,012 KB
testcase_45 AC 161 ms
160,124 KB
testcase_46 AC 151 ms
159,844 KB
testcase_47 AC 156 ms
159,908 KB
testcase_48 AC 150 ms
160,116 KB
testcase_49 AC 156 ms
159,868 KB
testcase_50 AC 397 ms
159,980 KB
testcase_51 AC 278 ms
160,120 KB
testcase_52 AC 600 ms
160,124 KB
testcase_53 AC 334 ms
160,124 KB
testcase_54 AC 591 ms
160,152 KB
testcase_55 AC 266 ms
160,128 KB
testcase_56 AC 360 ms
160,136 KB
testcase_57 AC 558 ms
160,180 KB
testcase_58 AC 420 ms
160,260 KB
testcase_59 AC 486 ms
160,128 KB
testcase_60 AC 630 ms
159,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = 18446744073709551615
inf = 4294967295
md = 10**9+7
# md = 998244353

def nHr(hn, hr):
    return nCr(hn+hr-1, hr-1)

def nPr(com_n, com_r):
    if com_r < 0: return 0
    if com_n < com_r: return 0
    return fac[com_n]*ifac[com_n-com_r]%md

def nCr(com_n, com_r):
    if com_r < 0: return 0
    if com_n < com_r: return 0
    return fac[com_n]*ifac[com_r]%md*ifac[com_n-com_r]%md

# 準備
n_max = 1000005
fac = [1]
for i in range(1, n_max+1): fac.append(fac[-1]*i%md)
ifac = [1]*(n_max+1)
ifac[n_max] = pow(fac[n_max], md-2, md)
for i in range(n_max-1, 1, -1): ifac[i] = ifac[i+1]*(i+1)%md

def factors(a):
    res = []
    for f in range(1, min(a, n)+1):
        if a%f == 0: res.append(f)
    return res

n, k, m = LI()

if m == 1:
    ans = 0
    for a in factors(k):
        a -= 1
        ans += nPr(n-1, a)*pow(n, n-1-a, md)%md
        ans %= md
    print(ans)
    exit()

ans = 0
if n > k: ans = nPr(n-2, k-1)*pow(n, n-k, md)%md

for a in range(1, min(k, n)):
    c = a+1
    if k%c == 0: c -= 1
    ans += nPr(n-2, a-1)*c%md*pow(n, n-1-a, md)%md
    ans %= md

print(ans)
0