結果

問題 No.1259 スイッチ
ユーザー mkawa2mkawa2
提出日時 2021-12-04 23:50:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,630 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 160,900 KB
最終ジャッジ日時 2023-09-21 13:02:47
合計ジャッジ時間 21,311 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
159,928 KB
testcase_01 AC 133 ms
160,040 KB
testcase_02 AC 135 ms
159,884 KB
testcase_03 AC 132 ms
159,924 KB
testcase_04 AC 140 ms
160,140 KB
testcase_05 AC 132 ms
159,928 KB
testcase_06 WA -
testcase_07 AC 132 ms
159,904 KB
testcase_08 AC 131 ms
159,888 KB
testcase_09 AC 131 ms
160,164 KB
testcase_10 AC 428 ms
160,260 KB
testcase_11 AC 596 ms
160,076 KB
testcase_12 AC 409 ms
160,448 KB
testcase_13 AC 292 ms
160,900 KB
testcase_14 AC 365 ms
160,336 KB
testcase_15 AC 285 ms
160,460 KB
testcase_16 AC 508 ms
160,284 KB
testcase_17 AC 357 ms
160,188 KB
testcase_18 AC 564 ms
160,452 KB
testcase_19 AC 560 ms
160,132 KB
testcase_20 AC 426 ms
160,212 KB
testcase_21 AC 615 ms
160,352 KB
testcase_22 AC 268 ms
160,388 KB
testcase_23 AC 552 ms
160,232 KB
testcase_24 AC 448 ms
160,096 KB
testcase_25 AC 440 ms
160,452 KB
testcase_26 AC 615 ms
160,024 KB
testcase_27 AC 526 ms
160,192 KB
testcase_28 AC 438 ms
160,096 KB
testcase_29 AC 518 ms
160,252 KB
testcase_30 AC 140 ms
160,104 KB
testcase_31 AC 141 ms
159,868 KB
testcase_32 AC 135 ms
160,016 KB
testcase_33 AC 147 ms
160,176 KB
testcase_34 AC 140 ms
159,932 KB
testcase_35 AC 141 ms
160,112 KB
testcase_36 AC 142 ms
159,928 KB
testcase_37 AC 141 ms
160,256 KB
testcase_38 AC 141 ms
159,920 KB
testcase_39 AC 145 ms
159,952 KB
testcase_40 AC 145 ms
159,876 KB
testcase_41 AC 143 ms
160,128 KB
testcase_42 AC 147 ms
159,940 KB
testcase_43 AC 142 ms
160,088 KB
testcase_44 AC 146 ms
159,900 KB
testcase_45 AC 147 ms
160,364 KB
testcase_46 AC 141 ms
160,188 KB
testcase_47 AC 146 ms
159,936 KB
testcase_48 AC 137 ms
159,876 KB
testcase_49 AC 147 ms
160,124 KB
testcase_50 AC 392 ms
160,588 KB
testcase_51 AC 269 ms
160,232 KB
testcase_52 AC 593 ms
160,264 KB
testcase_53 AC 330 ms
160,024 KB
testcase_54 AC 595 ms
160,192 KB
testcase_55 AC 260 ms
160,272 KB
testcase_56 AC 356 ms
160,264 KB
testcase_57 AC 556 ms
160,464 KB
testcase_58 AC 415 ms
160,156 KB
testcase_59 AC 482 ms
160,200 KB
testcase_60 AC 635 ms
160,276 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()
ff = set(factors(k))

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

ans = nPr(n-1, k)

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

print(ans)
0