結果
問題 | No.1785 Inequality Signs |
ユーザー | yudedako |
提出日時 | 2022-01-26 15:24:17 |
言語 | Scala(Beta) (3.4.0) |
結果 |
AC
|
実行時間 | 1,058 ms / 2,000 ms |
コード長 | 2,673 bytes |
コンパイル時間 | 13,688 ms |
コンパイル使用メモリ | 280,048 KB |
実行使用メモリ | 67,392 KB |
最終ジャッジ日時 | 2024-12-02 13:04:15 |
合計ジャッジ時間 | 69,567 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 897 ms
64,828 KB |
testcase_01 | AC | 935 ms
65,100 KB |
testcase_02 | AC | 1,016 ms
67,248 KB |
testcase_03 | AC | 1,018 ms
67,348 KB |
testcase_04 | AC | 897 ms
65,048 KB |
testcase_05 | AC | 981 ms
65,192 KB |
testcase_06 | AC | 1,027 ms
67,356 KB |
testcase_07 | AC | 919 ms
65,100 KB |
testcase_08 | AC | 1,013 ms
67,344 KB |
testcase_09 | AC | 938 ms
65,268 KB |
testcase_10 | AC | 1,003 ms
67,032 KB |
testcase_11 | AC | 968 ms
65,060 KB |
testcase_12 | AC | 983 ms
65,160 KB |
testcase_13 | AC | 994 ms
64,936 KB |
testcase_14 | AC | 986 ms
65,160 KB |
testcase_15 | AC | 1,000 ms
65,192 KB |
testcase_16 | AC | 974 ms
64,896 KB |
testcase_17 | AC | 1,012 ms
67,196 KB |
testcase_18 | AC | 1,022 ms
67,164 KB |
testcase_19 | AC | 983 ms
65,092 KB |
testcase_20 | AC | 1,010 ms
64,976 KB |
testcase_21 | AC | 986 ms
65,028 KB |
testcase_22 | AC | 947 ms
65,168 KB |
testcase_23 | AC | 961 ms
65,080 KB |
testcase_24 | AC | 1,029 ms
67,316 KB |
testcase_25 | AC | 983 ms
65,108 KB |
testcase_26 | AC | 974 ms
65,104 KB |
testcase_27 | AC | 1,034 ms
67,344 KB |
testcase_28 | AC | 1,052 ms
67,224 KB |
testcase_29 | AC | 1,058 ms
67,316 KB |
testcase_30 | AC | 1,030 ms
67,184 KB |
testcase_31 | AC | 1,020 ms
67,340 KB |
testcase_32 | AC | 1,024 ms
67,368 KB |
testcase_33 | AC | 897 ms
64,892 KB |
testcase_34 | AC | 926 ms
65,216 KB |
testcase_35 | AC | 925 ms
65,020 KB |
testcase_36 | AC | 1,001 ms
67,360 KB |
testcase_37 | AC | 981 ms
67,284 KB |
testcase_38 | AC | 984 ms
67,104 KB |
testcase_39 | AC | 949 ms
65,096 KB |
testcase_40 | AC | 964 ms
65,032 KB |
testcase_41 | AC | 985 ms
64,944 KB |
testcase_42 | AC | 1,006 ms
67,392 KB |
testcase_43 | AC | 1,021 ms
67,032 KB |
testcase_44 | AC | 1,017 ms
67,168 KB |
testcase_45 | AC | 974 ms
64,956 KB |
testcase_46 | AC | 997 ms
67,080 KB |
testcase_47 | AC | 966 ms
65,028 KB |
testcase_48 | AC | 995 ms
67,220 KB |
testcase_49 | AC | 925 ms
65,180 KB |
testcase_50 | AC | 1,013 ms
67,336 KB |
testcase_51 | AC | 932 ms
65,132 KB |
testcase_52 | AC | 923 ms
64,972 KB |
testcase_53 | AC | 932 ms
65,184 KB |
ソースコード
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)