結果

問題 No.1050 Zero (Maximum)
ユーザー wattaiheiwattaihei
提出日時 2020-05-08 23:01:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 881 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 77,376 KB
最終ジャッジ日時 2023-09-17 03:22:37
合計ジャッジ時間 3,877 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,464 KB
testcase_01 AC 78 ms
76,364 KB
testcase_02 AC 134 ms
76,784 KB
testcase_03 AC 121 ms
76,960 KB
testcase_04 AC 215 ms
76,692 KB
testcase_05 AC 227 ms
76,476 KB
testcase_06 AC 140 ms
76,480 KB
testcase_07 AC 155 ms
76,696 KB
testcase_08 AC 83 ms
76,360 KB
testcase_09 AC 114 ms
76,456 KB
testcase_10 AC 272 ms
76,908 KB
testcase_11 AC 211 ms
76,884 KB
testcase_12 AC 79 ms
76,448 KB
testcase_13 AC 72 ms
71,472 KB
testcase_14 AC 71 ms
71,420 KB
testcase_15 AC 71 ms
71,604 KB
testcase_16 AC 288 ms
76,840 KB
testcase_17 AC 313 ms
77,376 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