結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-05-02 12:08:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 474 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 76,552 KB
最終ジャッジ日時 2024-04-15 09:44:11
合計ジャッジ時間 7,079 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,036 KB
testcase_01 AC 48 ms
60,264 KB
testcase_02 AC 50 ms
63,360 KB
testcase_03 AC 41 ms
52,820 KB
testcase_04 AC 41 ms
52,808 KB
testcase_05 AC 164 ms
74,352 KB
testcase_06 AC 137 ms
73,040 KB
testcase_07 AC 203 ms
75,984 KB
testcase_08 AC 60 ms
63,960 KB
testcase_09 AC 58 ms
63,048 KB
testcase_10 AC 49 ms
61,128 KB
testcase_11 AC 317 ms
76,352 KB
testcase_12 AC 44 ms
52,944 KB
testcase_13 AC 50 ms
60,960 KB
testcase_14 AC 56 ms
62,308 KB
testcase_15 AC 340 ms
76,064 KB
testcase_16 AC 391 ms
76,300 KB
testcase_17 AC 377 ms
76,268 KB
testcase_18 AC 349 ms
76,264 KB
testcase_19 AC 350 ms
76,200 KB
testcase_20 AC 389 ms
76,552 KB
testcase_21 AC 380 ms
76,180 KB
testcase_22 AC 357 ms
76,412 KB
testcase_23 AC 312 ms
76,260 KB
testcase_24 AC 355 ms
76,420 KB
testcase_25 AC 474 ms
76,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#行列の乗算・累乗

mod = 10 ** 9 + 7

def mat_mul(a, b):
    n_a, m_a = len(a), len(a[0])
    n_b, m_b = len(b), len(b[0])
    res = [[0] * m_b for i in range(n_a)]
    for i in range(n_a):
        for k in range(m_a):
            for j in range(m_b):
                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