結果

問題 No.1102 Remnants
ユーザー yudedakoyudedako
提出日時 2022-01-26 21:09:45
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,231 ms / 2,000 ms
コード長 2,400 bytes
コンパイル時間 14,841 ms
コンパイル使用メモリ 252,528 KB
実行使用メモリ 85,520 KB
最終ジャッジ日時 2023-08-25 03:42:04
合計ジャッジ時間 48,537 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 927 ms
61,860 KB
testcase_01 AC 932 ms
62,208 KB
testcase_02 AC 924 ms
62,144 KB
testcase_03 AC 925 ms
61,736 KB
testcase_04 AC 933 ms
62,228 KB
testcase_05 AC 1,191 ms
77,480 KB
testcase_06 AC 1,046 ms
62,368 KB
testcase_07 AC 1,231 ms
85,520 KB
testcase_08 AC 963 ms
62,304 KB
testcase_09 AC 990 ms
62,612 KB
testcase_10 AC 985 ms
62,312 KB
testcase_11 AC 985 ms
62,712 KB
testcase_12 AC 996 ms
62,068 KB
testcase_13 AC 985 ms
62,448 KB
testcase_14 AC 1,122 ms
67,396 KB
testcase_15 AC 1,094 ms
66,412 KB
testcase_16 AC 1,228 ms
79,984 KB
testcase_17 AC 1,206 ms
79,520 KB
testcase_18 AC 1,206 ms
81,856 KB
testcase_19 AC 1,074 ms
64,456 KB
testcase_20 AC 1,031 ms
62,776 KB
testcase_21 AC 1,176 ms
69,724 KB
testcase_22 AC 1,191 ms
77,740 KB
testcase_23 AC 1,177 ms
74,208 KB
testcase_24 AC 1,176 ms
67,588 KB
testcase_25 AC 1,221 ms
81,884 KB
testcase_26 AC 984 ms
62,352 KB
testcase_27 AC 1,056 ms
64,456 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