結果

問題 No.1815 K色問題
ユーザー 259_Momone259_Momone
提出日時 2022-09-18 03:44:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,335 bytes
コンパイル時間 802 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 63,204 KB
最終ジャッジ日時 2024-03-13 11:33:37
合計ジャッジ時間 13,942 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 510 ms
42,836 KB
testcase_01 AC 32 ms
10,240 KB
testcase_02 AC 508 ms
42,836 KB
testcase_03 WA -
testcase_04 AC 30 ms
10,240 KB
testcase_05 AC 500 ms
42,836 KB
testcase_06 WA -
testcase_07 AC 367 ms
13,700 KB
testcase_08 AC 1,565 ms
58,688 KB
testcase_09 AC 324 ms
18,052 KB
testcase_10 AC 460 ms
21,808 KB
testcase_11 AC 1,047 ms
56,468 KB
testcase_12 AC 31 ms
10,240 KB
testcase_13 AC 30 ms
10,240 KB
testcase_14 AC 1,820 ms
63,204 KB
testcase_15 AC 1,822 ms
63,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ans = [0] * (K + 1)

if N == 1:
    ans = [i * pow(i, M - 1, 1000000007) % 1000000007 for i in range(K + 1)]
elif N == 2:
    ans = [i * (i - 1) * pow((i - 3) * i + 3, M - 1, 1000000007) % 1000000007 for i in range(K + 1)]
else:
    import numpy as np
    ans = np.array([(i - 2) * ((i - 3) * i + 5) % 1000000007 for i in range(K + 1)])
    b = np.array([(((i - 6) * i + 13) * i - 11) % 1000000007 * (i - 1) % 1000000007 for i in range(K + 1)])
    c = np.array([i * (i - 1) * (i - 1) % 1000000007 for i in range(K + 1)])
    d = np.array([((i - 3) * i + 1) % 1000000007 * i * (i - 1) % 1000000007 for i in range(K + 1)])
    n = M - 1
    while n:
        if n & 1:
            c = ans * c - d
            c = c % 1000000007
            d = b * d
        else:
            d = ans * d - b * c
        d = d % 1000000007
        ans = ans * ans - 2 * b
        ans = ans % 1000000007
        b = b * b
        b = b % 1000000007
        n >>= 1
    ans = c.tolist()

coef = [1] * (K + 1)

for i in range(K):
    coef[i + 1] = coef[i] * (K - i) % 1000000007

c = 1
for i in range(K + 1, 0, -1):
    c = -c * i % 1000000007
    coef[i - 1] = coef[i - 1] * c % 1000000007

ret = 0
for i in range(K + 1):
    ret += ans[i] * coef[i]

ret *= pow(coef[-1], 1000000005, 1000000007)
print(ret % 1000000007)
0