結果
問題 | No.1815 K色問題 |
ユーザー | 259_Momone |
提出日時 | 2022-09-18 03:44:51 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,829 ms / 2,000 ms |
コード長 | 1,339 bytes |
コンパイル時間 | 115 ms |
コンパイル使用メモリ | 12,032 KB |
実行使用メモリ | 63,204 KB |
最終ジャッジ日時 | 2024-03-13 11:33:44 |
合計ジャッジ時間 | 13,074 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 472 ms
42,836 KB |
testcase_01 | AC | 29 ms
10,240 KB |
testcase_02 | AC | 477 ms
42,836 KB |
testcase_03 | AC | 29 ms
10,240 KB |
testcase_04 | AC | 30 ms
10,240 KB |
testcase_05 | AC | 472 ms
42,836 KB |
testcase_06 | AC | 1,512 ms
25,408 KB |
testcase_07 | AC | 361 ms
13,700 KB |
testcase_08 | AC | 1,514 ms
58,688 KB |
testcase_09 | AC | 316 ms
18,052 KB |
testcase_10 | AC | 457 ms
21,808 KB |
testcase_11 | AC | 1,017 ms
56,468 KB |
testcase_12 | AC | 30 ms
10,240 KB |
testcase_13 | AC | 30 ms
10,240 KB |
testcase_14 | AC | 1,829 ms
63,204 KB |
testcase_15 | AC | 1,794 ms
63,204 KB |
ソースコード
N, M, K = map(int, input().split()) ans = [0] * (K + 1) if N == 1: ans = [i * pow(i - 1, 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)