結果

問題 No.1050 Zero (Maximum)
ユーザー wattaiheiwattaihei
提出日時 2020-05-08 23:00:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,440 ms / 2,000 ms
コード長 881 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 8,392 KB
最終ジャッジ日時 2023-09-17 03:22:33
合計ジャッジ時間 9,433 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,936 KB
testcase_01 AC 18 ms
7,788 KB
testcase_02 AC 297 ms
8,344 KB
testcase_03 AC 199 ms
8,292 KB
testcase_04 AC 857 ms
8,284 KB
testcase_05 AC 947 ms
8,316 KB
testcase_06 AC 393 ms
8,304 KB
testcase_07 AC 498 ms
8,312 KB
testcase_08 AC 43 ms
7,776 KB
testcase_09 AC 243 ms
8,340 KB
testcase_10 AC 1,224 ms
8,208 KB
testcase_11 AC 840 ms
8,392 KB
testcase_12 AC 25 ms
7,852 KB
testcase_13 AC 16 ms
7,780 KB
testcase_14 AC 16 ms
7,840 KB
testcase_15 AC 16 ms
7,792 KB
testcase_16 AC 1,327 ms
8,216 KB
testcase_17 AC 1,440 ms
8,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9+7
# matrix power
def matintersection(matA, matB, mod):
    length = len(matA)
    matR = [[0]*length for _ in range(length)]
    for i in range(length):
        for j in range(length):
            for k in range(length):
                matR[i][j] += matA[i][k]*matB[k][j] % mod
                matR[i][j] %= mod
    return matR

def power_mat(matA, n, mod):
    bi = str(format(n,"b"))#2進表現に
    length = len(matA)
    res = [[1 if i == j else 0 for i in range(length)] for j in range(length)]
    for i in range(len(bi)):
        res = matintersection(res, res, mod)
        if bi[i] == "1":
            res = matintersection(res, matA, mod)
    return res

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

D = [[0]*N for _ in range(N)]
for n in range(N):
    for m in range(N):
        D[(m*n)%N][n] += 1
        D[(m+n)%N][n] += 1

A = power_mat(D, K, mod)
print(A[0][0])
0