結果

問題 No.840 ほむほむほむら
ユーザー keymoon
提出日時 2019-03-29 15:43:20
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,027 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 44,644 KB
最終ジャッジ日時 2024-11-07 01:15:25
合計ジャッジ時間 18,712 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 8 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

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

for i in range(k**3):
	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

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

mod = 1000000007

while n > 0:
	if n % 2 == 1:
		res = np.mod(np.matmul(res, matrix), mod)
	matrix = np.mod((np.matmul(matrix, matrix)),mod)
	n = n // 2


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

print(numRes % mod)
0