結果

問題 No.1749 ラムドスウイルスの感染拡大
ユーザー yudedakoyudedako
提出日時 2022-01-25 00:00:26
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,115 ms / 2,000 ms
コード長 2,584 bytes
コンパイル時間 14,562 ms
コンパイル使用メモリ 274,468 KB
実行使用メモリ 65,100 KB
最終ジャッジ日時 2024-05-08 20:46:16
合計ジャッジ時間 46,027 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 933 ms
65,100 KB
testcase_01 AC 929 ms
63,260 KB
testcase_02 AC 937 ms
63,300 KB
testcase_03 AC 932 ms
63,204 KB
testcase_04 AC 1,022 ms
63,736 KB
testcase_05 AC 938 ms
63,328 KB
testcase_06 AC 944 ms
63,296 KB
testcase_07 AC 936 ms
63,256 KB
testcase_08 AC 933 ms
63,348 KB
testcase_09 AC 932 ms
63,304 KB
testcase_10 AC 966 ms
63,320 KB
testcase_11 AC 960 ms
63,292 KB
testcase_12 AC 1,115 ms
63,728 KB
testcase_13 AC 946 ms
63,308 KB
testcase_14 AC 988 ms
63,680 KB
testcase_15 AC 1,000 ms
63,692 KB
testcase_16 AC 1,012 ms
63,712 KB
testcase_17 AC 1,022 ms
63,700 KB
testcase_18 AC 1,020 ms
63,648 KB
testcase_19 AC 1,034 ms
63,788 KB
testcase_20 AC 970 ms
63,304 KB
testcase_21 AC 949 ms
63,444 KB
testcase_22 AC 935 ms
63,316 KB
testcase_23 AC 940 ms
63,436 KB
testcase_24 AC 936 ms
63,292 KB
testcase_25 AC 978 ms
63,636 KB
testcase_26 AC 962 ms
63,164 KB
testcase_27 AC 963 ms
63,372 KB
testcase_28 AC 1,013 ms
63,608 KB
testcase_29 AC 1,015 ms
63,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.io.StdIn.*

object ModInt:
  opaque type ModInt = Long
  extension (value: Long)
    inline def asModInt(using inline mod: Int): ModInt =  value % mod
  extension (value: Int)
    inline def asModInt(using inline mod: Int): ModInt = value % mod
  trait Converter[T]:
    inline def convert(value: T)(using inline mod: Int): ModInt
  inline given Converter[Int] with
    override inline def convert(value: Int)(using inline mod: Int) = value.asModInt
  inline given Converter[Long] with
    override inline def convert(value: Long)(using inline mod: Int) = value.asModInt
  inline given Converter[ModInt] with
    override inline def convert(value: ModInt)(using inline mod: Int) = value
  extension (modInt: ModInt)
    inline def asLong(using inline mod: Int): Long = (modInt + mod) % mod
    inline def inverse(using inline mod: Int): ModInt = modInt.powMod(mod - 2)
    inline def powMod(exp: Int)(using inline mod: Int): ModInt =
      var result = 1L
      var base = modInt
      var e = exp
      while e > 0 do
        if (e & 1) == 1 then
          result = result * base % mod
        base = base * base % mod
        e >>= 1
      result
    inline def powMod(exp: Long)(using inline mod: Int): ModInt =
      var result = 1L
      var base = modInt
      var e = exp
      while e > 0 do
        if (e & 1) == 1 then
          result = result * base % mod
        base = base * base % mod
        e >>= 1
      result
  extension [L: Converter, R: Converter] (left: L)
    inline def +(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) + summon[Converter[R]].convert(right)).asModInt
    inline def -(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) - summon[Converter[R]].convert(right)).asModInt
    inline def *(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right)).asModInt
    inline def /(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right).inverse).asModInt


@main def main =
  import ModInt._
  inline given mod: Int = 998244353
  val Array(n, m, t) = readLine().split(' ').map(_.toInt)
  val roads = Array.fill(m){
    val Array(u, v) = readLine().split(' ').map(_.toInt)
    (u, v)
  }
  val current = Array.fill(n){0.asModInt}
  current(0) = 1.asModInt
  for _ <- 0 until t do
    val next = Array.fill(n){0.asModInt}
    for (u, v) <- roads do
      next(v) += current(u)
      next(u) += current(v)
    next.copyToArray(current)
  println(current(0).asLong)
0