結果
問題 | No.1785 Inequality Signs |
ユーザー |
|
提出日時 | 2022-01-26 15:24:17 |
言語 | Scala(Beta) (3.6.2) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,673 bytes |
コンパイル時間 | 14,010 ms |
コンパイル使用メモリ | 280,748 KB |
実行使用メモリ | 247,092 KB |
最終ジャッジ日時 | 2025-01-29 22:44:21 |
合計ジャッジ時間 | 182,738 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | TLE * 2 |
other | TLE * 52 |
ソースコード
import scala.annotation.tailrecimport scala.io.StdIn.*import scala.math.*object ModInt:opaque type ModInt = Longextension (value: Long)inline def asModInt(using inline mod: Int): ModInt = value % modextension (value: Int)inline def asModInt(using inline mod: Int): ModInt = value % modtrait Converter[T]:inline def convert(value: T)(using inline mod: Int): ModIntinline given Converter[Int] withoverride inline def convert(value: Int)(using inline mod: Int) = value.asModIntinline given Converter[Long] withoverride inline def convert(value: Long)(using inline mod: Int) = value.asModIntinline given Converter[ModInt] withoverride inline def convert(value: ModInt)(using inline mod: Int) = valueextension (modInt: ModInt)inline def asLong(using inline mod: Int): Long = (modInt + mod) % modinline def inverse(using inline mod: Int): ModInt = modInt.powMod(mod - 2)inline def powMod(exp: Long)(using inline mod: Int): ModInt =var result = 1Lvar base = modIntvar e = expwhile e > 0 doif (e & 1) == 1 thenresult = result * base % modbase = base * base % mode >>= 1resultinline def powMod(exp: Int)(using inline mod: Int): ModInt = powMod(exp.toLong)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)).asModIntinline def -(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) - summon[Converter[R]].convert(right)).asModIntinline def *(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right)).asModIntinline 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 = 1000000007val Array(n, k) = readLine().split(' ').map(_.toInt)val factorial = Array.fill(n + 1){1.asModInt}for i <- 2 to n dofactorial(i) = i * factorial(i - 1)val inverse = factorial.clone()inverse(n) = inverse(n).inversefor i <- n to 2 by -1 doinverse(i - 1) = i * inverse(i)def combination(n: Int, r: Int): ModInt = factorial(n) * inverse(r) * inverse(n - r)var current = (k + n - 1 to k by -1).foldLeft(1.asModInt){_ * _} * inverse(n)val maxLt = min(n - 1, k - 1)var result = currentfor lt <- 1 to maxLt docurrent = current * (k - lt) * (n - lt) / ((k + n - lt).asModInt * lt)result += currentprintln(result.asLong)