結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー yudedakoyudedako
提出日時 2020-08-28 18:50:08
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 14,679 ms
コンパイル使用メモリ 444,604 KB
実行使用メモリ 72,768 KB
最終ジャッジ日時 2024-04-26 12:25:45
合計ジャッジ時間 25,814 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 432 ms
62,232 KB
testcase_01 AC 445 ms
69,428 KB
testcase_02 AC 449 ms
68,996 KB
testcase_03 AC 434 ms
70,572 KB
testcase_04 AC 452 ms
71,560 KB
testcase_05 AC 414 ms
60,192 KB
testcase_06 AC 434 ms
72,640 KB
testcase_07 AC 458 ms
72,708 KB
testcase_08 AC 456 ms
72,424 KB
testcase_09 AC 459 ms
72,696 KB
testcase_10 AC 425 ms
65,668 KB
testcase_11 AC 426 ms
65,488 KB
testcase_12 AC 447 ms
71,924 KB
testcase_13 AC 443 ms
72,336 KB
testcase_14 AC 462 ms
72,768 KB
testcase_15 AC 423 ms
55,896 KB
testcase_16 AC 392 ms
55,624 KB
testcase_17 AC 379 ms
54,932 KB
testcase_18 AC 384 ms
54,940 KB
testcase_19 AC 391 ms
56,436 KB
testcase_20 AC 394 ms
56,232 KB
testcase_21 AC 372 ms
54,216 KB
testcase_22 AC 427 ms
62,288 KB
testcase_23 AC 327 ms
52,048 KB
testcase_24 AC 324 ms
52,100 KB
testcase_25 AC 327 ms
51,992 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:14:24: warning: name shadowed: n
    val combination = {n: Int, r: Int ->
                       ^

ソースコード

diff #

import kotlin.math.min

fun main() {
    val mod = 998244353
    val (n, m, a, b) = readLine()!!.trim().split(' ').map(String::toInt)
    val factorial = LongArray(m + n + 1){1L}
    val div = LongArray(m + n + 1){1L}
    val inverse = LongArray(m + n + 1){1L}
    for (i in 2 until factorial.size) {
        factorial[i] = i * factorial[i - 1] % mod
        div[i] = (mod - mod / i) * div[mod % i] % mod
        inverse[i] = div[i] * inverse[i - 1] % mod
    }
    val combination = {n: Int, r: Int ->
        if (n >= r) factorial[n] * inverse[r] % mod * inverse[n - r] % mod
        else 0
    }
    val result = (1 .. m).map {smaller ->
        val greater = min(smaller + b, m)
        val diff = greater - a * n.toLong() + a - smaller
        if (diff >= 0)
            combination(diff.toInt() + n - 1, n - 1)
        else
            0
    }
    println(result.sum() % mod * factorial[n] % mod)
}
0