結果
問題 | No.1521 Playing Musical Chairs Alone |
ユーザー | NatsubiSogan |
提出日時 | 2021-05-05 01:15:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 402 ms / 2,000 ms |
コード長 | 2,581 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,116 KB |
実行使用メモリ | 76,704 KB |
最終ジャッジ日時 | 2024-10-05 03:04:30 |
合計ジャッジ時間 | 5,671 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
53,092 KB |
testcase_01 | AC | 43 ms
62,708 KB |
testcase_02 | AC | 45 ms
64,732 KB |
testcase_03 | AC | 39 ms
53,844 KB |
testcase_04 | AC | 40 ms
53,668 KB |
testcase_05 | AC | 152 ms
76,100 KB |
testcase_06 | AC | 130 ms
76,404 KB |
testcase_07 | AC | 186 ms
76,360 KB |
testcase_08 | AC | 55 ms
67,484 KB |
testcase_09 | AC | 52 ms
65,964 KB |
testcase_10 | AC | 43 ms
63,724 KB |
testcase_11 | AC | 268 ms
76,412 KB |
testcase_12 | AC | 35 ms
53,664 KB |
testcase_13 | AC | 41 ms
63,740 KB |
testcase_14 | AC | 44 ms
64,788 KB |
testcase_15 | AC | 295 ms
76,368 KB |
testcase_16 | AC | 356 ms
76,496 KB |
testcase_17 | AC | 334 ms
76,452 KB |
testcase_18 | AC | 313 ms
76,376 KB |
testcase_19 | AC | 305 ms
76,444 KB |
testcase_20 | AC | 354 ms
76,608 KB |
testcase_21 | AC | 320 ms
76,312 KB |
testcase_22 | AC | 307 ms
76,500 KB |
testcase_23 | AC | 275 ms
76,104 KB |
testcase_24 | AC | 300 ms
76,564 KB |
testcase_25 | AC | 402 ms
76,704 KB |
ソースコード
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])