結果
問題 | No.2199 lower_bound and upper_bound |
ユーザー | 👑 箱 |
提出日時 | 2022-05-05 04:12:56 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 520 ms / 2,000 ms |
コード長 | 2,045 bytes |
コンパイル時間 | 16,912 ms |
コンパイル使用メモリ | 455,572 KB |
実行使用メモリ | 139,720 KB |
最終ジャッジ日時 | 2024-04-15 16:07:53 |
合計ジャッジ時間 | 29,213 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 487 ms
139,336 KB |
testcase_01 | AC | 488 ms
139,160 KB |
testcase_02 | AC | 500 ms
139,380 KB |
testcase_03 | AC | 494 ms
139,436 KB |
testcase_04 | AC | 490 ms
139,436 KB |
testcase_05 | AC | 493 ms
139,200 KB |
testcase_06 | AC | 499 ms
139,316 KB |
testcase_07 | AC | 496 ms
139,136 KB |
testcase_08 | AC | 490 ms
139,188 KB |
testcase_09 | AC | 490 ms
139,500 KB |
testcase_10 | AC | 516 ms
139,600 KB |
testcase_11 | AC | 503 ms
139,176 KB |
testcase_12 | AC | 492 ms
139,428 KB |
testcase_13 | AC | 520 ms
139,680 KB |
testcase_14 | AC | 488 ms
139,168 KB |
testcase_15 | AC | 495 ms
139,392 KB |
testcase_16 | AC | 507 ms
139,540 KB |
testcase_17 | AC | 501 ms
139,304 KB |
testcase_18 | AC | 505 ms
139,400 KB |
testcase_19 | AC | 512 ms
139,580 KB |
testcase_20 | AC | 515 ms
139,624 KB |
testcase_21 | AC | 504 ms
139,408 KB |
testcase_22 | AC | 503 ms
139,332 KB |
testcase_23 | AC | 504 ms
139,200 KB |
testcase_24 | AC | 517 ms
139,720 KB |
ソースコード
fun main() { val facSize = 600000 val arrFac = Array(facSize) { ModInt(1) } val arrInvfac = Array(facSize) { ModInt(1) } for (i in 1 until facSize) { arrFac[i] = arrFac[i - 1] * ModInt(i) } arrInvfac[facSize - 1] = arrFac[facSize - 1].inv() for (i in facSize - 2 downTo 1) { arrInvfac[i] = arrInvfac[i + 1] * ModInt(i + 1) } fun binom(n: Long, k: Long): ModInt { return if (k in 0..n) { arrFac[n.toInt()] * arrInvfac[k.toInt()] * arrInvfac[(n - k).toInt()] } else { ModInt(0) } } val (n, l, u) = readLongs() var ans = ModInt(0) for (m in l..u) { ans += binom(2 * n + m - 1, n - 1) - binom(2 * n + m - 1, n + u + 1) } println(ans) } // region ModInt class ModInt(x: Long) { companion object { const val MOD = 998244353L //const val MOD = 1000000007L } 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" } } // endregion fun readLongs() = readln().split(" ").map { it.toLong() }