結果
問題 | No.1749 ラムドスウイルスの感染拡大 |
ユーザー | 箱星 |
提出日時 | 2021-10-13 13:21:03 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 604 ms / 2,000 ms |
コード長 | 2,970 bytes |
コンパイル時間 | 17,420 ms |
コンパイル使用メモリ | 454,308 KB |
実行使用メモリ | 152,148 KB |
最終ジャッジ日時 | 2024-06-10 06:53:38 |
合計ジャッジ時間 | 22,673 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 244 ms
50,148 KB |
testcase_01 | AC | 261 ms
50,132 KB |
testcase_02 | AC | 250 ms
50,020 KB |
testcase_03 | AC | 256 ms
50,188 KB |
testcase_04 | AC | 345 ms
84,352 KB |
testcase_05 | AC | 259 ms
50,128 KB |
testcase_06 | AC | 253 ms
50,736 KB |
testcase_07 | AC | 256 ms
50,524 KB |
testcase_08 | AC | 262 ms
50,216 KB |
testcase_09 | AC | 250 ms
50,368 KB |
testcase_10 | AC | 341 ms
108,072 KB |
testcase_11 | AC | 344 ms
108,048 KB |
testcase_12 | AC | 488 ms
141,384 KB |
testcase_13 | AC | 252 ms
50,924 KB |
testcase_14 | AC | 292 ms
54,156 KB |
testcase_15 | AC | 307 ms
62,104 KB |
testcase_16 | AC | 316 ms
70,716 KB |
testcase_17 | AC | 446 ms
108,756 KB |
testcase_18 | AC | 604 ms
152,148 KB |
testcase_19 | AC | 354 ms
107,836 KB |
testcase_20 | AC | 289 ms
55,060 KB |
testcase_21 | AC | 262 ms
52,132 KB |
testcase_22 | AC | 250 ms
50,120 KB |
testcase_23 | AC | 253 ms
50,528 KB |
testcase_24 | AC | 254 ms
50,724 KB |
testcase_25 | AC | 342 ms
107,680 KB |
testcase_26 | AC | 274 ms
62,160 KB |
testcase_27 | AC | 266 ms
56,568 KB |
testcase_28 | AC | 339 ms
84,176 KB |
testcase_29 | AC | 344 ms
83,952 KB |
ソースコード
import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val m = nextInt() val t = nextInt() val adj = Array(n) { mutableListOf<Int>() } for (i in 0 until m) { val v1 = nextInt() val v2 = nextInt() adj[v1].add(v2) adj[v2].add(v1) } val num = Array(t + 1) { Array(n) { false to ModInt(0) } } num[0][0] = true to ModInt(1) fun f(i: Int, v: Int): ModInt { if (i == 0) return num[i][v].second if (num[i][v].first) return num[i][v].second var ret = ModInt(0) for (w in adj[v]) { ret += f(i - 1, w) } num[i][v] = true to ret return ret } println(f(t, 0)) } // region ModInt class ModInt(x: Long) { companion object { //const val MOD = 1000000007L const val MOD = 998244353L } constructor(y: Int) : this(y.toLong()) val x = (x % MOD + MOD) % MOD operator fun plus(other: ModInt): ModInt { return ModInt(x + other.x) } operator fun minus(other: ModInt): ModInt { return ModInt(x - other.x) } operator fun times(other: ModInt): ModInt { return ModInt(x * other.x) } operator fun div(other: ModInt): ModInt { return this * other.inv() } fun pow(exp: Long): ModInt { if (exp == 0L) return ModInt(1L) var a = pow(exp shr 1) a *= a if (exp and 1L == 0L) return a return this * a } fun inv(): ModInt { return this.pow(MOD - 2) } override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false other as ModInt if (x != other.x) return false return true } override fun hashCode(): Int { return x.hashCode() } override fun toString(): String { return "$x" } } fun Long.toModInt(): ModInt { return ModInt(this) } fun Int.toModInt(): ModInt { return ModInt(this) } fun binomSimple(n: Long, k: Long): ModInt { var numer = ModInt(1) var denom = ModInt(1) for (i in 0 until k) { numer *= ModInt(n - i) denom *= ModInt(k - i) } return numer / denom } // endregion fun main() { Thread(null, { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() }, "solve", 1.shl(26)) .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } } .apply { start() }.join() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion