結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-05-05 01:15:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 2,581 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 76,940 KB
最終ジャッジ日時 2024-04-15 09:45:05
合計ジャッジ時間 7,678 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
53,788 KB
testcase_01 AC 62 ms
63,156 KB
testcase_02 AC 64 ms
64,836 KB
testcase_03 AC 48 ms
52,852 KB
testcase_04 AC 51 ms
53,548 KB
testcase_05 AC 193 ms
76,300 KB
testcase_06 AC 170 ms
76,616 KB
testcase_07 AC 232 ms
76,088 KB
testcase_08 AC 75 ms
66,004 KB
testcase_09 AC 74 ms
66,860 KB
testcase_10 AC 60 ms
63,356 KB
testcase_11 AC 345 ms
76,516 KB
testcase_12 AC 49 ms
53,760 KB
testcase_13 AC 56 ms
63,120 KB
testcase_14 AC 60 ms
65,196 KB
testcase_15 AC 368 ms
76,644 KB
testcase_16 AC 418 ms
76,304 KB
testcase_17 AC 418 ms
76,676 KB
testcase_18 AC 389 ms
76,292 KB
testcase_19 AC 371 ms
76,528 KB
testcase_20 AC 417 ms
76,812 KB
testcase_21 AC 402 ms
76,584 KB
testcase_22 AC 391 ms
76,708 KB
testcase_23 AC 340 ms
76,220 KB
testcase_24 AC 375 ms
76,416 KB
testcase_25 AC 506 ms
76,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7
#行列ライブラリ
class Matrix:
    def __init__(self, n, m, mat=None):
        self.n = n
        self.m = m
        self.mat = [[0] * self.m for i in range(self.n)]
        if mat:
            for i in range(self.n):
                self.mat[i] = mat[i]
    
    def __getitem__(self, key):
        if isinstance(key, slice):
            return self.mat[key]
        else:
            assert key >= 0
            return self.mat[key]

    def id(n):
        res = Matrix(n, n)
        for i in range(n):
            res[i][i] = 1
        return res

    def __len__(self):
        return len(self.mat)
    
    def __str__(self):
        return "\n".join(" ".join(map(str, self[i])) for i in range(self.n))

    def times(self, k):
        res = [[0] * self.m for i in range(self.n)]
        for i in range(self.n):
            for j in range(self.m):
                res[i][j] = k * self[i][j] % mod
        return Matrix(self.n, self.m, res)

    def __pos__(self):
        return self

    def __neg__(self):
        return self.times(-1)

    def __add__(self, other):
        res = [[0] * self.m for i in range(self.n)]
        for i in range(self.n):
            for j in range(self.m):
                res[i][j] = (self[i][j] + other[i][j]) % mod
        return Matrix(self.n, self.m, res)
    
    def __sub__(self, other):
        res = [[0] * self.m for i in range(self.n)]
        for i in range(self.n):
            for j in range(self.m):
                res[i][j] = (self[i][j] - other[i][j]) % mod
        return Matrix(self.n, self.m, res)

    def __mul__(self, other):
        if other.__class__ == Matrix:
            res = [[0] * other.m for i in range(self.n)]
            for i in range(self.n):
                for k in range(self.m):
                    for j in range(other.m):
                        res[i][j] += self[i][k] * other[k][j]
                        res[i][j] %= mod
            return Matrix(self.n, other.m, res)
        else:
            return self.times(other)
    
    def __rmul__(self, other):
        return self.times(other)

    def __pow__(self, k):
        tmp = Matrix(self.n, self.n, self.mat)
        res = Matrix.id(self.n)
        while k:
            if k & 1:
                res *= tmp
            tmp *= tmp
            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 = Matrix(n, n, G)

G **= k

for i in range(n):
    print(G[0][i])
0