結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー maguroflymagurofly
提出日時 2021-11-19 21:55:12
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 950 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 11,288 KB
実行使用メモリ 22,212 KB
最終ジャッジ日時 2023-08-30 08:19:18
合計ジャッジ時間 5,414 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
22,212 KB
testcase_01 AC 80 ms
15,036 KB
testcase_02 AC 80 ms
15,288 KB
testcase_03 AC 86 ms
15,052 KB
testcase_04 AC 469 ms
15,256 KB
testcase_05 AC 78 ms
15,236 KB
testcase_06 AC 79 ms
15,340 KB
testcase_07 AC 79 ms
15,316 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0