結果

問題 No.2023 Tiling is Fun
ユーザー 箱星
提出日時 2022-06-07 20:29:07
言語 Kotlin
(2.1.0)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 13,318 ms
コンパイル使用メモリ 434,348 KB
実行使用メモリ 76,032 KB
最終ジャッジ日時 2024-07-19 11:42:19
合計ジャッジ時間 20,142 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

fun main() {
    val (a, b) = readLongs()
    fun fac(n: Long) = (1..n).map { ModInt(it) }.fold(ModInt(1), ModInt::times)
    println(fac(a + b - 2) / (fac(a - 1) * fac(b - 1)))
}

// region ModInt
class ModInt(x: Long) {
    companion object {
        const val MOD = 998244353L
    }

    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 toString(): String {
        return "$x"
    }
}
// endregion

fun readLongs() = readln().split(" ").map { it.toLong() }
0