結果

問題 No.1102 Remnants
ユーザー yudedakoyudedako
提出日時 2022-01-26 21:09:45
言語 Scala(Beta)
(3.6.2)
結果
AC  
実行時間 1,346 ms / 2,000 ms
コード長 2,400 bytes
コンパイル時間 15,466 ms
コンパイル使用メモリ 268,420 KB
実行使用メモリ 84,608 KB
最終ジャッジ日時 2024-12-23 15:50:24
合計ジャッジ時間 50,409 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 986 ms
63,200 KB
testcase_01 AC 985 ms
63,216 KB
testcase_02 AC 981 ms
63,088 KB
testcase_03 AC 990 ms
63,332 KB
testcase_04 AC 980 ms
63,168 KB
testcase_05 AC 1,278 ms
80,188 KB
testcase_06 AC 1,108 ms
65,236 KB
testcase_07 AC 1,337 ms
84,608 KB
testcase_08 AC 1,019 ms
63,344 KB
testcase_09 AC 1,055 ms
63,484 KB
testcase_10 AC 997 ms
63,284 KB
testcase_11 AC 1,038 ms
63,360 KB
testcase_12 AC 1,076 ms
63,248 KB
testcase_13 AC 1,058 ms
63,404 KB
testcase_14 AC 1,226 ms
70,212 KB
testcase_15 AC 1,164 ms
68,176 KB
testcase_16 AC 1,320 ms
81,272 KB
testcase_17 AC 1,311 ms
80,976 KB
testcase_18 AC 1,307 ms
82,432 KB
testcase_19 AC 1,139 ms
67,440 KB
testcase_20 AC 1,102 ms
63,336 KB
testcase_21 AC 1,269 ms
71,936 KB
testcase_22 AC 1,278 ms
78,004 KB
testcase_23 AC 1,292 ms
76,396 KB
testcase_24 AC 1,205 ms
70,172 KB
testcase_25 AC 1,346 ms
82,576 KB
testcase_26 AC 1,047 ms
63,268 KB
testcase_27 AC 1,132 ms
65,980 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 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)

0