結果
問題 |
No.840 ほむほむほむら
|
ユーザー |
![]() |
提出日時 | 2019-03-29 17:25:31 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,447 bytes |
コンパイル時間 | 99 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 50,852 KB |
最終ジャッジ日時 | 2024-11-07 01:16:24 |
合計ジャッジ時間 | 9,090 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | WA * 3 TLE * 1 -- * 21 |
ソースコード
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)