結果
問題 | No.1750 ラムドスウイルスの感染拡大-hard |
ユーザー | NatsubiSogan |
提出日時 | 2021-11-19 23:31:24 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,609 bytes |
コンパイル時間 | 314 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 70,144 KB |
最終ジャッジ日時 | 2024-06-10 11:05:48 |
合計ジャッジ時間 | 3,692 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
ソースコード
import typing class Matrix: def __init__(self, n: int, m: int, mat: typing.Union[list, None] = None, mod: int = 998244353) -> None: self.n = n self.m = m self.mat = [[0] * self.m for i in range(self.n)] self.mod = mod if mat: for i in range(self.n): self.mat[i] = mat[i] def is_square(self) -> None: return self.n == self.m def __getitem__(self, key: int) -> int: if isinstance(key, slice): return self.mat[key] else: assert key >= 0 return self.mat[key] def __mul__(self, other: typing.Union["Matrix", int]) -> "Matrix": 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] for i in range(self.n): for j in range(other.m): res[i][j] %= self.mod return Matrix(self.n, other.m, res) else: return self.times(other) def __rmul__(self, other: typing.Union["Matrix", int]) -> "Matrix": return self.times(other) def __pow__(self, k: int) -> "Matrix": tmp = Matrix(self.n, self.n, self.mat) res = Matrix(n, n) for i in range(n): res[i][i] = 1 while k: if k & 1: res *= tmp tmp *= tmp k >>= 1 return res def main(): import sys input = sys.stdin.buffer.readable n, m, t = map(int, input().split()) G = [[0] * n for i in range(n)] for _ in range(m): a, b = map(int, input().split()) G[a][b] = 1 G[b][a] = 1 G = Matrix(n, n, G) G **= t b = [[0] * n for i in range(n)] b[0][0] = 1 G *= Matrix(n, n, b) print(G.mat[0][0]) if __name__ == '__main__': main()