結果

問題 No.1836 Max Matrix
ユーザー yudedakoyudedako
提出日時 2022-02-21 23:27:53
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,034 ms / 2,000 ms
コード長 2,940 bytes
コンパイル時間 11,204 ms
コンパイル使用メモリ 258,256 KB
実行使用メモリ 62,364 KB
最終ジャッジ日時 2023-09-12 13:58:40
合計ジャッジ時間 29,662 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 923 ms
61,768 KB
testcase_01 AC 916 ms
61,596 KB
testcase_02 AC 1,009 ms
62,256 KB
testcase_03 AC 1,013 ms
61,632 KB
testcase_04 AC 978 ms
61,788 KB
testcase_05 AC 997 ms
61,956 KB
testcase_06 AC 983 ms
61,884 KB
testcase_07 AC 1,006 ms
61,500 KB
testcase_08 AC 967 ms
61,924 KB
testcase_09 AC 1,008 ms
61,836 KB
testcase_10 AC 988 ms
62,216 KB
testcase_11 AC 923 ms
61,924 KB
testcase_12 AC 1,034 ms
62,032 KB
testcase_13 AC 975 ms
62,364 KB
testcase_14 AC 975 ms
61,636 KB
testcase_15 AC 949 ms
61,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn.*
import scala.util.chaining.*
import scala.math.*
import scala.reflect.{ClassTag, classTag}
import scala.util.*
import scala.annotation.tailrec
object ModInt:
  opaque type ModInt = Long
  inline def zero: ModInt = 0
  inline def one: ModInt = 1
  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 =
      var x = modInt
      var y = mod.toLong
      var a = 1L
      var b = 0L
      var c = 0L
      var d = 1L
      while y != 0 do
        val q = x / y
        val e = a - c * q
        val f = b - d * q
        a = c
        b = d
        c = e
        d = f
        x = y
        y = c * modInt + d * mod
      require(x.abs == 1L)
      if x == 1 then a % mod else -a % mod
    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 = 998244353
  val Array(height, width, valueMax) = readLine.split(' ').map(_.toInt)
  var result = ModInt.zero
  for min <- 1 to valueMax do
    result += ((valueMax - min + 1).asModInt.powMod(height) - (valueMax - min).asModInt.powMod(height)) * ((valueMax - min + 1).asModInt.powMod(width) - (valueMax - min).asModInt.powMod(width))
  println(result.asLong)
0