結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-04-14 18:31:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 899 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 18,340 KB
最終ジャッジ日時 2024-04-15 09:43:56
合計ジャッジ時間 8,013 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
17,828 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 39 ms
10,752 KB
testcase_03 AC 33 ms
10,752 KB
testcase_04 AC 32 ms
10,752 KB
testcase_05 TLE -
testcase_06 AC 1,762 ms
11,392 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ライブラリ: 行列の計算(乗算/累乗)

mod = 10 ** 9 + 7

def mat_mul(a, b):
    n = len(a)
    res = [[0] * n for i in range(n)]
    for i in range(n):
        for k in range(n):
            for j in range(n):
                res[i][j] += a[i][k] * b[k][j]
                res[i][j] %= mod
    return res

def mat_pow(a, k):
    if k == 1: return a
    n = len(a)
    res = [[0] * n for i in range(n)]
    for i in range(n):
        res[i][i] = 1
    while k:
        if k & 1:
            res = mat_mul(res, a)
        a = mat_mul(a, a)
        k >>= 1
    return res

#入力
n, k, l = map(int, input().split())

#隣接行列の構築
G = [[0] * n for i in range(n)]
for i in range(n):
    for j in range(1, l + 1):
        G[i][(i + j) % n] = 1

#行列累乗でパスの数を計算
G_ans = mat_pow(G, k)

#各 i について答えを出力
for i in range(n):
    print(G_ans[0][i])
0