結果
問題 |
No.1750 ラムドスウイルスの感染拡大-hard
|
ユーザー |
|
提出日時 | 2021-11-19 21:55:12 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 950 bytes |
コンパイル時間 | 858 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 27,904 KB |
最終ジャッジ日時 | 2025-01-01 17:01:43 |
合計ジャッジ時間 | 69,387 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 TLE * 22 |
コンパイルメッセージ
Syntax OK
ソースコード
N, M, T = gets.split.map(&:to_i) MOD = 998244353 class ModMatrix attr_reader :n, :m, :rows def initialize(rows) @n, @m, @rows = rows.size, rows[0].size, rows end def self.id(n) new((0 ... n).map { |i| (0 ... n).map { |j| (i == j) ? 1 : 0 } }) end def [](i, j) @rows[i][j] end def +(other) self.class.new(@rows.map.with_index { |row, i| row.map.with_index { |x, j| (x + other[i, j]) % MOD } }) end def *(other) self.class.new((0 ... @n).map { |i| (0 ... other.n).map { |j| (0 ... @m).sum { |k| self[i, k] * other[k, j] } % MOD } }) end def **(e) r = self.class.id(@n) x = self while e > 0 r *= x if (e & 1) == 1 x *= x e >>= 1 end r end end mat = Array.new(N) { Array.new(N, 0) } M.times do s, t = gets.split.map(&:to_i) mat[s][t] = 1 mat[t][s] = 1 end mat = ModMatrix.new(mat)**T puts mat[0, 0] % MOD