結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー 👑 rin204rin204
提出日時 2022-04-15 17:31:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 77,352 KB
最終ジャッジ日時 2023-08-26 06:23:46
合計ジャッジ時間 5,970 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,908 KB
testcase_01 AC 78 ms
75,772 KB
testcase_02 AC 81 ms
76,132 KB
testcase_03 AC 75 ms
71,208 KB
testcase_04 AC 72 ms
71,016 KB
testcase_05 AC 161 ms
76,988 KB
testcase_06 AC 134 ms
76,708 KB
testcase_07 AC 171 ms
77,300 KB
testcase_08 AC 88 ms
76,480 KB
testcase_09 AC 85 ms
76,272 KB
testcase_10 AC 77 ms
76,132 KB
testcase_11 AC 241 ms
77,200 KB
testcase_12 AC 70 ms
71,048 KB
testcase_13 AC 78 ms
76,092 KB
testcase_14 AC 80 ms
76,228 KB
testcase_15 AC 244 ms
77,276 KB
testcase_16 AC 275 ms
77,088 KB
testcase_17 AC 281 ms
77,200 KB
testcase_18 AC 264 ms
76,968 KB
testcase_19 AC 269 ms
77,104 KB
testcase_20 AC 275 ms
77,116 KB
testcase_21 AC 278 ms
77,068 KB
testcase_22 AC 284 ms
77,244 KB
testcase_23 AC 229 ms
77,352 KB
testcase_24 AC 292 ms
77,220 KB
testcase_25 AC 274 ms
77,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[:]
        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 = [C[i][:] for i in range(n)]
        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