結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー H3PO4H3PO4
提出日時 2022-08-31 09:29:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,443 ms / 2,000 ms
コード長 827 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 85,132 KB
最終ジャッジ日時 2024-04-25 14:21:16
合計ジャッジ時間 16,669 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,720 KB
testcase_01 AC 41 ms
60,728 KB
testcase_02 AC 44 ms
63,180 KB
testcase_03 AC 35 ms
53,480 KB
testcase_04 AC 35 ms
53,264 KB
testcase_05 AC 443 ms
79,580 KB
testcase_06 AC 304 ms
78,312 KB
testcase_07 AC 581 ms
80,972 KB
testcase_08 AC 86 ms
75,932 KB
testcase_09 AC 84 ms
76,116 KB
testcase_10 AC 41 ms
60,712 KB
testcase_11 AC 958 ms
82,816 KB
testcase_12 AC 34 ms
52,668 KB
testcase_13 AC 40 ms
60,648 KB
testcase_14 AC 42 ms
61,452 KB
testcase_15 AC 1,076 ms
83,336 KB
testcase_16 AC 1,250 ms
84,424 KB
testcase_17 AC 1,172 ms
83,592 KB
testcase_18 AC 1,104 ms
84,072 KB
testcase_19 AC 1,126 ms
84,140 KB
testcase_20 AC 1,170 ms
83,932 KB
testcase_21 AC 1,443 ms
83,916 KB
testcase_22 AC 1,050 ms
83,308 KB
testcase_23 AC 920 ms
82,584 KB
testcase_24 AC 1,161 ms
84,008 KB
testcase_25 AC 1,371 ms
85,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7


# PyPy用行列累乗 https://qiita.com/ophhdn/items/e6451ec5983939ecbc5b から拝借しています。

def mat_mul(a, b):
    I, J, K = len(a), len(b[0]), len(b)
    c = [[0] * J for _ in range(I)]
    for i in range(I):
        for j in range(J):
            for k in range(K):
                c[i][j] += a[i][k] * b[k][j]
            c[i][j] %= MOD
    return c


def mat_pow(x, n):
    y = [[0] * len(x) for _ in range(len(x))]

    for i in range(len(x)):
        y[i][i] = 1

    while n > 0:
        if n & 1:
            y = mat_mul(x, y)
        x = mat_mul(x, x)
        n >>= 1

    return y


N, K, L = map(int, input().split())

matr = [[0] * N for _ in range(N)]
for i in range(N):
    for j in range(L):
        matr[i][(i + 1 + j) % N] = 1

res = mat_pow(matr, K)[0]
print(*res, sep="\n")
0