結果
問題 | No.1750 ラムドスウイルスの感染拡大-hard |
ユーザー | 草苺奶昔 |
提出日時 | 2023-03-14 17:50:25 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,809 bytes |
コンパイル時間 | 207 ms |
コンパイル使用メモリ | 82,376 KB |
実行使用メモリ | 85,888 KB |
最終ジャッジ日時 | 2024-09-18 08:20:21 |
合計ジャッジ時間 | 24,428 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
67,456 KB |
testcase_01 | AC | 58 ms
67,584 KB |
testcase_02 | AC | 62 ms
68,736 KB |
testcase_03 | AC | 62 ms
69,760 KB |
testcase_04 | AC | 125 ms
78,080 KB |
testcase_05 | AC | 58 ms
67,200 KB |
testcase_06 | AC | 58 ms
67,328 KB |
testcase_07 | AC | 55 ms
67,712 KB |
testcase_08 | AC | 389 ms
78,512 KB |
testcase_09 | AC | 396 ms
78,848 KB |
testcase_10 | AC | 400 ms
78,580 KB |
testcase_11 | AC | 341 ms
78,132 KB |
testcase_12 | AC | 414 ms
78,456 KB |
testcase_13 | AC | 414 ms
78,364 KB |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | AC | 1,983 ms
85,336 KB |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | AC | 1,409 ms
83,564 KB |
testcase_21 | AC | 1,638 ms
83,328 KB |
testcase_22 | AC | 356 ms
79,340 KB |
testcase_23 | AC | 1,854 ms
83,652 KB |
testcase_24 | AC | 282 ms
78,560 KB |
testcase_25 | AC | 582 ms
80,300 KB |
testcase_26 | AC | 229 ms
78,264 KB |
testcase_27 | AC | 71 ms
74,024 KB |
testcase_28 | AC | 85 ms
78,004 KB |
testcase_29 | AC | 69 ms
74,240 KB |
testcase_30 | AC | 336 ms
79,872 KB |
testcase_31 | AC | 326 ms
80,012 KB |
testcase_32 | AC | 322 ms
79,488 KB |
testcase_33 | AC | 326 ms
79,864 KB |
ソースコード
from typing import List M = List[List[int]] class MatPow: __slots__ = ("_n", "_mod", "_base", "_cacheLevel", "_useCache", "_cache") def __init__(self, base: M, mod=1000000007, cacheLevel=4): n = len(base) b = [0] * n * n for i in range(n): for j in range(n): b[i * n + j] = base[i][j] useCache = cacheLevel >= 2 self._n = n self._mod = mod self._base = b self._cacheLevel = cacheLevel self._useCache = useCache if useCache: self._cache = [[] for _ in range(cacheLevel - 1)] def pow(self, exp: int) -> M: if not self._useCache: return self._powWithOutCache(exp) if len(self._cache[0]) == 0: self._cache[0].append(self._base) for i in range(1, self._cacheLevel - 1): self._cache[i].append(self._mul(self._cache[i - 1][0], self._base)) e = self._eye(self._n) div = 0 while exp: if div == len(self._cache[0]): self._cache[0].append( self._mul(self._cache[self._cacheLevel - 2][div - 1], self._cache[0][div - 1]) ) for i in range(1, self._cacheLevel - 1): self._cache[i].append(self._mul(self._cache[i - 1][div], self._cache[0][div])) mod = exp % self._cacheLevel if mod: e = self._mul(e, self._cache[mod - 1][div]) exp //= self._cacheLevel div += 1 return self._to2D(e) def _mul(self, mat1: List[int], mat2: List[int]) -> List[int]: n = self._n res = [0] * n * n for i in range(n): for k in range(n): for j in range(n): res[i * n + j] = ( res[i * n + j] + mat1[i * n + k] * mat2[k * n + j] ) % self._mod return res def _powWithOutCache(self, exp: int) -> M: e = self._eye(self._n) b = self._base[:] while exp: if exp & 1: e = self._mul(e, b) exp >>= 1 b = self._mul(b, b) return self._to2D(e) def _eye(self, n: int) -> List[int]: res = [0] * n * n for i in range(n): res[i * n + i] = 1 return res def _to2D(self, mat: List[int]) -> M: n = self._n return [mat[i * n : (i + 1) * n] for i in range(n)] def __pow__(self, exp: int) -> M: return self.pow(exp) n, m, k = map(int, input().split()) adjMatrix = [[0] * n for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) adjMatrix[u][v] = 1 adjMatrix[v][u] = 1 P = MatPow(adjMatrix, 998244353, cacheLevel=4) res = P.pow(k)[0][0] print(res)