結果

問題 No.1800 Random XOR
ユーザー yudedakoyudedako
提出日時 2022-01-24 23:23:27
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,027 ms / 2,000 ms
コード長 2,344 bytes
コンパイル時間 15,758 ms
コンパイル使用メモリ 266,648 KB
実行使用メモリ 63,084 KB
最終ジャッジ日時 2024-05-08 20:03:58
合計ジャッジ時間 33,323 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,006 ms
63,020 KB
testcase_01 AC 1,003 ms
63,000 KB
testcase_02 AC 959 ms
62,876 KB
testcase_03 AC 960 ms
62,992 KB
testcase_04 AC 954 ms
63,044 KB
testcase_05 AC 956 ms
62,984 KB
testcase_06 AC 1,027 ms
62,888 KB
testcase_07 AC 949 ms
63,084 KB
testcase_08 AC 1,011 ms
62,908 KB
testcase_09 AC 962 ms
63,080 KB
testcase_10 AC 962 ms
62,948 KB
testcase_11 AC 955 ms
62,996 KB
testcase_12 AC 968 ms
62,788 KB
testcase_13 AC 958 ms
62,988 KB
testcase_14 AC 953 ms
62,880 KB
testcase_15 AC 997 ms
62,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable
import scala.io.StdIn.*
import scala.math.min
import ModInt._
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: Int)(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: 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
  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 =
  inline given mod: Int = 1000000007
  val Array(n, m) = readLine().split(' ').map(_.toLong)
  val max = 2L.asModInt.powMod(m) - 1
  val result = max / 2
  println(result.asLong)
0