結果

問題 No.1050 Zero (Maximum)
ユーザー rkyiolklorkyiolklo
提出日時 2020-05-09 10:10:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,459 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 10,732 KB
実行使用メモリ 8,388 KB
最終ジャッジ日時 2023-09-18 15:50:47
合計ジャッジ時間 9,958 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,764 KB
testcase_01 AC 19 ms
7,816 KB
testcase_02 AC 290 ms
8,196 KB
testcase_03 AC 201 ms
8,388 KB
testcase_04 AC 854 ms
8,288 KB
testcase_05 AC 953 ms
8,200 KB
testcase_06 AC 395 ms
8,304 KB
testcase_07 AC 490 ms
8,208 KB
testcase_08 AC 43 ms
7,868 KB
testcase_09 AC 242 ms
8,268 KB
testcase_10 AC 1,208 ms
8,176 KB
testcase_11 AC 838 ms
8,200 KB
testcase_12 AC 25 ms
7,788 KB
testcase_13 AC 16 ms
7,828 KB
testcase_14 AC 16 ms
7,760 KB
testcase_15 AC 16 ms
7,768 KB
testcase_16 AC 1,326 ms
8,348 KB
testcase_17 AC 1,459 ms
8,328 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