結果

問題 No.1050 Zero (Maximum)
ユーザー rkyiolklorkyiolklo
提出日時 2020-05-09 10:11:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 1,218 ms
コンパイル使用メモリ 86,568 KB
実行使用メモリ 77,048 KB
最終ジャッジ日時 2023-09-18 15:49:56
合計ジャッジ時間 4,929 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,320 KB
testcase_01 AC 83 ms
76,284 KB
testcase_02 AC 134 ms
76,524 KB
testcase_03 AC 125 ms
77,024 KB
testcase_04 AC 218 ms
76,652 KB
testcase_05 AC 232 ms
76,244 KB
testcase_06 AC 146 ms
76,428 KB
testcase_07 AC 158 ms
76,876 KB
testcase_08 AC 87 ms
76,344 KB
testcase_09 AC 121 ms
76,440 KB
testcase_10 AC 275 ms
76,572 KB
testcase_11 AC 215 ms
76,496 KB
testcase_12 AC 82 ms
76,292 KB
testcase_13 AC 73 ms
71,124 KB
testcase_14 AC 72 ms
71,400 KB
testcase_15 AC 75 ms
71,220 KB
testcase_16 AC 295 ms
76,692 KB
testcase_17 AC 319 ms
77,048 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