結果

問題 No.1785 Inequality Signs
ユーザー yudedakoyudedako
提出日時 2022-01-26 15:24:17
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,092 ms / 2,000 ms
コード長 2,673 bytes
コンパイル時間 16,230 ms
コンパイル使用メモリ 251,376 KB
実行使用メモリ 64,520 KB
最終ジャッジ日時 2023-08-24 20:08:42
合計ジャッジ時間 76,183 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 936 ms
61,956 KB
testcase_01 AC 988 ms
62,472 KB
testcase_02 AC 1,064 ms
64,228 KB
testcase_03 AC 1,079 ms
64,376 KB
testcase_04 AC 954 ms
62,244 KB
testcase_05 AC 1,015 ms
62,348 KB
testcase_06 AC 1,078 ms
64,348 KB
testcase_07 AC 972 ms
62,080 KB
testcase_08 AC 1,072 ms
64,400 KB
testcase_09 AC 984 ms
61,976 KB
testcase_10 AC 1,065 ms
62,908 KB
testcase_11 AC 1,002 ms
62,236 KB
testcase_12 AC 1,037 ms
62,376 KB
testcase_13 AC 979 ms
62,028 KB
testcase_14 AC 1,027 ms
62,300 KB
testcase_15 AC 1,025 ms
62,228 KB
testcase_16 AC 1,020 ms
61,916 KB
testcase_17 AC 1,063 ms
64,376 KB
testcase_18 AC 1,056 ms
64,520 KB
testcase_19 AC 1,019 ms
62,548 KB
testcase_20 AC 1,065 ms
62,228 KB
testcase_21 AC 1,031 ms
62,312 KB
testcase_22 AC 994 ms
62,428 KB
testcase_23 AC 1,014 ms
62,268 KB
testcase_24 AC 1,086 ms
64,376 KB
testcase_25 AC 1,029 ms
62,292 KB
testcase_26 AC 1,026 ms
62,452 KB
testcase_27 AC 1,073 ms
64,492 KB
testcase_28 AC 1,078 ms
64,344 KB
testcase_29 AC 1,078 ms
64,480 KB
testcase_30 AC 1,069 ms
64,416 KB
testcase_31 AC 1,092 ms
64,216 KB
testcase_32 AC 1,085 ms
64,176 KB
testcase_33 AC 936 ms
62,032 KB
testcase_34 AC 972 ms
62,584 KB
testcase_35 AC 995 ms
62,120 KB
testcase_36 AC 1,070 ms
64,304 KB
testcase_37 AC 1,041 ms
64,432 KB
testcase_38 AC 1,052 ms
64,104 KB
testcase_39 AC 1,020 ms
62,104 KB
testcase_40 AC 1,049 ms
62,416 KB
testcase_41 AC 1,055 ms
62,148 KB
testcase_42 AC 1,069 ms
64,332 KB
testcase_43 AC 1,075 ms
64,292 KB
testcase_44 AC 1,079 ms
64,176 KB
testcase_45 AC 1,023 ms
61,956 KB
testcase_46 AC 1,043 ms
64,380 KB
testcase_47 AC 1,029 ms
62,248 KB
testcase_48 AC 1,052 ms
64,244 KB
testcase_49 AC 972 ms
61,972 KB
testcase_50 AC 1,066 ms
64,108 KB
testcase_51 AC 976 ms
62,064 KB
testcase_52 AC 971 ms
62,564 KB
testcase_53 AC 983 ms
61,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.annotation.tailrec
import scala.io.StdIn.*
import scala.math.*

object ModInt:
  opaque type ModInt = Long
  extension (value: Long)
    inline def asModInt(using inline mod: Int): ModInt =  value % mod
  extension (value: Int)
    inline def asModInt(using inline mod: Int): ModInt = value % mod
  trait Converter[T]:
    inline def convert(value: T)(using inline mod: Int): ModInt
  inline given Converter[Int] with
    override inline def convert(value: Int)(using inline mod: Int) = value.asModInt
  inline given Converter[Long] with
    override inline def convert(value: Long)(using inline mod: Int) = value.asModInt
  inline given Converter[ModInt] with
    override inline def convert(value: ModInt)(using inline mod: Int) = value
  extension (modInt: ModInt)
    inline def asLong(using inline mod: Int): Long = (modInt + mod) % mod
    inline def inverse(using inline mod: Int): ModInt = modInt.powMod(mod - 2)
    inline def powMod(exp: Long)(using inline mod: Int): ModInt =
      var result = 1L
      var base = modInt
      var e = exp
      while e > 0 do
        if (e & 1) == 1 then
          result = result * base % mod
        base = base * base % mod
        e >>= 1
      result
    inline 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)).asModInt
    inline def -(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) - summon[Converter[R]].convert(right)).asModInt
    inline def *(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right)).asModInt
    inline 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 = 1000000007
  val Array(n, k) = readLine().split(' ').map(_.toInt)
  val factorial = Array.fill(n + 1){1.asModInt}
  for i <- 2 to n do
    factorial(i) = i * factorial(i - 1)
  val inverse = factorial.clone()
  inverse(n) = inverse(n).inverse
  for i <- n to 2 by -1 do
    inverse(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 = current
  for lt <- 1 to maxLt do
    current = current * (k - lt) * (n - lt) / ((k + n - lt).asModInt * lt)
    result += current
  println(result.asLong)

0