結果

問題 No.1749 ラムドスウイルスの感染拡大
ユーザー yudedakoyudedako
提出日時 2022-01-25 00:00:26
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,042 ms / 2,000 ms
コード長 2,584 bytes
コンパイル時間 10,148 ms
コンパイル使用メモリ 267,816 KB
実行使用メモリ 63,312 KB
最終ジャッジ日時 2023-08-21 15:17:45
合計ジャッジ時間 42,180 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 919 ms
62,244 KB
testcase_01 AC 914 ms
62,200 KB
testcase_02 AC 917 ms
62,264 KB
testcase_03 AC 924 ms
62,104 KB
testcase_04 AC 1,017 ms
62,912 KB
testcase_05 AC 914 ms
61,972 KB
testcase_06 AC 930 ms
62,288 KB
testcase_07 AC 925 ms
62,436 KB
testcase_08 AC 920 ms
62,252 KB
testcase_09 AC 961 ms
62,248 KB
testcase_10 AC 961 ms
62,548 KB
testcase_11 AC 949 ms
62,388 KB
testcase_12 AC 1,018 ms
62,460 KB
testcase_13 AC 928 ms
62,236 KB
testcase_14 AC 980 ms
62,932 KB
testcase_15 AC 985 ms
62,512 KB
testcase_16 AC 998 ms
62,580 KB
testcase_17 AC 1,024 ms
62,904 KB
testcase_18 AC 1,030 ms
62,768 KB
testcase_19 AC 1,042 ms
62,448 KB
testcase_20 AC 946 ms
62,428 KB
testcase_21 AC 947 ms
62,500 KB
testcase_22 AC 911 ms
63,312 KB
testcase_23 AC 918 ms
62,068 KB
testcase_24 AC 926 ms
62,236 KB
testcase_25 AC 960 ms
62,220 KB
testcase_26 AC 960 ms
62,448 KB
testcase_27 AC 952 ms
62,172 KB
testcase_28 AC 1,010 ms
62,732 KB
testcase_29 AC 1,016 ms
63,028 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