結果

問題 No.1259 スイッチ
ユーザー mkawa2mkawa2
提出日時 2021-12-05 00:25:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 620 ms / 2,000 ms
コード長 1,642 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 160,756 KB
最終ジャッジ日時 2023-09-21 13:08:16
合計ジャッジ時間 20,359 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
160,092 KB
testcase_01 AC 131 ms
159,912 KB
testcase_02 AC 133 ms
160,392 KB
testcase_03 AC 131 ms
160,040 KB
testcase_04 AC 129 ms
159,972 KB
testcase_05 AC 128 ms
159,976 KB
testcase_06 AC 128 ms
159,928 KB
testcase_07 AC 131 ms
159,972 KB
testcase_08 AC 131 ms
160,184 KB
testcase_09 AC 128 ms
159,940 KB
testcase_10 AC 415 ms
160,240 KB
testcase_11 AC 582 ms
160,224 KB
testcase_12 AC 400 ms
160,248 KB
testcase_13 AC 286 ms
160,304 KB
testcase_14 AC 354 ms
160,736 KB
testcase_15 AC 280 ms
160,264 KB
testcase_16 AC 499 ms
160,340 KB
testcase_17 AC 346 ms
160,196 KB
testcase_18 AC 555 ms
159,956 KB
testcase_19 AC 550 ms
159,944 KB
testcase_20 AC 417 ms
160,216 KB
testcase_21 AC 596 ms
160,640 KB
testcase_22 AC 263 ms
160,756 KB
testcase_23 AC 542 ms
160,352 KB
testcase_24 AC 438 ms
160,252 KB
testcase_25 AC 428 ms
160,168 KB
testcase_26 AC 606 ms
160,332 KB
testcase_27 AC 510 ms
160,220 KB
testcase_28 AC 428 ms
160,184 KB
testcase_29 AC 510 ms
160,008 KB
testcase_30 AC 139 ms
159,880 KB
testcase_31 AC 141 ms
159,964 KB
testcase_32 AC 137 ms
160,160 KB
testcase_33 AC 144 ms
159,980 KB
testcase_34 AC 139 ms
160,548 KB
testcase_35 AC 141 ms
159,908 KB
testcase_36 AC 140 ms
159,924 KB
testcase_37 AC 142 ms
160,072 KB
testcase_38 AC 141 ms
160,100 KB
testcase_39 AC 146 ms
159,900 KB
testcase_40 AC 146 ms
160,172 KB
testcase_41 AC 142 ms
160,040 KB
testcase_42 AC 145 ms
159,964 KB
testcase_43 AC 140 ms
160,512 KB
testcase_44 AC 145 ms
160,048 KB
testcase_45 AC 146 ms
159,940 KB
testcase_46 AC 139 ms
160,028 KB
testcase_47 AC 147 ms
160,032 KB
testcase_48 AC 138 ms
160,100 KB
testcase_49 AC 145 ms
160,288 KB
testcase_50 AC 383 ms
160,252 KB
testcase_51 AC 265 ms
160,196 KB
testcase_52 AC 585 ms
160,204 KB
testcase_53 AC 320 ms
160,208 KB
testcase_54 AC 579 ms
160,264 KB
testcase_55 AC 255 ms
160,372 KB
testcase_56 AC 348 ms
160,192 KB
testcase_57 AC 544 ms
160,216 KB
testcase_58 AC 406 ms
159,948 KB
testcase_59 AC 475 ms
160,268 KB
testcase_60 AC 620 ms
160,188 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 = 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