結果

問題 No.840 ほむほむほむら
ユーザー keymoonkeymoon
提出日時 2019-03-29 17:25:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,447 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 88,444 KB
最終ジャッジ日時 2024-04-24 16:36:34
合計ジャッジ時間 9,579 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

#誤差死する
n,k = map(int,input().split())
size = k**3
matrix = np.zeros((size, size), dtype = int)

for i in range(size):
	val = i
	aCount = val % k
	val = val // k
	abCount = val % k
	val = val // k
	abcCount = val % k

	#aが追加された時
	newACount = (aCount + 1) % k
	newABCount = abCount
	newABCCount = abcCount
	matrix[i, (newABCCount * k + newABCount) * k + newACount] += 1

	#bが追加された時
	newACount = aCount
	newABCount = (abCount + aCount) % k
	newABCCount = abcCount
	matrix[i, (newABCCount * k + newABCount) * k + newACount] += 1

	#cが追加された時
	newACount = aCount
	newABCount = abCount
	newABCCount = (abcCount + abCount) % k
	matrix[i, (newABCCount * k + newABCount) * k + newACount] += 1


mod = 1000000007
univ_format = np.frompyfunc(lambda x: x % mod, 1, 1)

print(matrix)
res = np.zeros((1, k**3), dtype = int)
res[0, 0] = 1

def stupidMul(a, b, h, w, size):
    res = np.zeros((h, w), dtype = int)
    for i in range(h):
        for j in range(w):
            for k in range(size):
                res[i, j] += a[i, k] * b[k, j]
                res[i, j] %= mod
    return res
    


while n > 0:
	if n % 2 == 1:
		res = univ_format(stupidMul(res, matrix, 1, size, size))
	matrix = univ_format(stupidMul(matrix, matrix,  size, size, size))
	#print(matrix)
	#print(matrix.dtype)
	n = n // 2


numRes = 0
for i in range(k**2):
	numRes = (numRes + res[0, i]) % mod

print(numRes)
0