結果
問題 | No.1102 Remnants |
ユーザー | yudedako |
提出日時 | 2022-01-26 21:09:45 |
言語 | Scala(Beta) (3.4.0) |
結果 |
AC
|
実行時間 | 1,124 ms / 2,000 ms |
コード長 | 2,400 bytes |
コンパイル時間 | 14,801 ms |
コンパイル使用メモリ | 264,592 KB |
実行使用メモリ | 84,512 KB |
最終ジャッジ日時 | 2024-06-06 04:25:59 |
合計ジャッジ時間 | 39,665 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 774 ms
64,996 KB |
testcase_01 | AC | 782 ms
64,880 KB |
testcase_02 | AC | 781 ms
64,968 KB |
testcase_03 | AC | 801 ms
65,160 KB |
testcase_04 | AC | 784 ms
64,984 KB |
testcase_05 | AC | 1,071 ms
81,336 KB |
testcase_06 | AC | 871 ms
65,132 KB |
testcase_07 | AC | 1,124 ms
84,512 KB |
testcase_08 | AC | 816 ms
65,116 KB |
testcase_09 | AC | 825 ms
65,212 KB |
testcase_10 | AC | 797 ms
65,116 KB |
testcase_11 | AC | 826 ms
65,292 KB |
testcase_12 | AC | 826 ms
64,908 KB |
testcase_13 | AC | 830 ms
65,036 KB |
testcase_14 | AC | 965 ms
70,028 KB |
testcase_15 | AC | 958 ms
69,268 KB |
testcase_16 | AC | 1,028 ms
81,852 KB |
testcase_17 | AC | 1,015 ms
83,176 KB |
testcase_18 | AC | 1,031 ms
82,576 KB |
testcase_19 | AC | 905 ms
69,360 KB |
testcase_20 | AC | 868 ms
65,348 KB |
testcase_21 | AC | 982 ms
71,824 KB |
testcase_22 | AC | 998 ms
79,892 KB |
testcase_23 | AC | 989 ms
77,228 KB |
testcase_24 | AC | 933 ms
70,140 KB |
testcase_25 | AC | 1,035 ms
82,336 KB |
testcase_26 | AC | 819 ms
65,152 KB |
testcase_27 | AC | 885 ms
67,180 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 a = readLine().split(' ').map(_.toInt) val combination = Array.fill(n){1.asModInt} for i <- 1 until n do combination(i) = combination(i - 1) * (k + i) / i var result = 0.asModInt for i <- 0 until n do val current = a(i) * combination(i) * combination(n - i - 1) result += current println(result.asLong)