結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー 👑 rin204rin204
提出日時 2022-04-15 17:30:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 86,632 KB
実行使用メモリ 78,768 KB
最終ジャッジ日時 2023-08-26 06:23:32
合計ジャッジ時間 8,611 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,568 KB
testcase_01 AC 88 ms
76,088 KB
testcase_02 AC 104 ms
77,752 KB
testcase_03 AC 85 ms
71,604 KB
testcase_04 AC 85 ms
71,420 KB
testcase_05 AC 212 ms
77,864 KB
testcase_06 AC 177 ms
78,204 KB
testcase_07 AC 224 ms
77,932 KB
testcase_08 AC 117 ms
77,900 KB
testcase_09 AC 122 ms
77,816 KB
testcase_10 AC 100 ms
76,656 KB
testcase_11 AC 308 ms
78,552 KB
testcase_12 AC 83 ms
71,484 KB
testcase_13 AC 92 ms
76,004 KB
testcase_14 AC 110 ms
77,764 KB
testcase_15 AC 325 ms
78,608 KB
testcase_16 AC 361 ms
78,440 KB
testcase_17 AC 368 ms
78,608 KB
testcase_18 AC 338 ms
78,596 KB
testcase_19 AC 356 ms
78,728 KB
testcase_20 AC 372 ms
78,196 KB
testcase_21 AC 359 ms
78,768 KB
testcase_22 AC 380 ms
78,540 KB
testcase_23 AC 299 ms
78,512 KB
testcase_24 AC 374 ms
78,624 KB
testcase_25 AC 362 ms
78,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy
MOD = 10 ** 9 + 7

def matpow(A, B, w):
    l = len(A)
    while w:
        if w & 1:
            C = [0] * l
            for i in range(l):
                for j in range(l):
                    C[i] += A[i][j] * B[j]
                    C[i] %= MOD
            B = C.copy()
        C = [[0] * l for _ in range(l)]
        for i in range(l):
            for j in range(l):
                for k in range(l):
                    C[i][j] += A[i][k] * A[k][j]
                    C[i][j] %= MOD
        A = deepcopy(C)
        w >>= 1
    return B

n, k, l = map(int, input().split())
B = [0] * n
B[0] = 1
A = [[0] * n for _ in range(n)]
for i in range(n):
    for j in range(1, l + 1):
        A[(i + j) % n][i] = 1

B = matpow(A, B, k)
print(*B, sep="\n")
0