結果

問題 No.1864 Shortest Paths Counting
ユーザー yudedako
提出日時 2022-03-15 22:13:13
言語 Scala(Beta)
(3.6.2)
結果
TLE  
実行時間 -
コード長 4,371 bytes
コンパイル時間 14,689 ms
コンパイル使用メモリ 270,216 KB
実行使用メモリ 66,952 KB
最終ジャッジ日時 2024-09-22 14:33:31
合計ジャッジ時間 29,163 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import java.io.PrintWriter
import scala.collection.mutable.*
import scala.io.StdIn.*
import scala.util.chaining.*
import scala.math.*
import scala.reflect.ClassTag
import scala.util.*
import scala.annotation.tailrec
import scala.collection.mutable
object ModInt:
opaque type ModInt = Long
inline def zero: ModInt = 0
inline def one: ModInt = 1
extension (value: Long)
inline def toModInt(using inline mod: Int): ModInt = value % mod
inline def unsafeAsModInt: ModInt = value
extension (value: Int)
inline def toModInt(using inline mod: Int): ModInt = value % mod
inline def unsafeAsModInt: ModInt = value
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.toModInt
inline given Converter[Long] with
override inline def convert(value: Long)(using inline mod: Int) = value.toModInt
inline given Converter[ModInt] with
override inline def convert(value: ModInt)(using inline mod: Int) = value
extension (modInt: ModInt)
inline def value(using inline mod: Int): Long = (modInt + mod) % mod
inline def rawValue: Long = modInt
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 pow(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 pow(exp: Int)(using inline mod: Int): ModInt = pow(exp.toLong)
inline def powMod[B: Converter] (base: B, exp: Int)(using inline mod: Int): ModInt = summon[Converter[B]].convert(base).pow(exp)
inline def powMod[B: Converter] (base: B, exp: Long)(using inline mod: Int): ModInt = summon[Converter[B]].convert(base).pow(exp)
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)).toModInt
inline def -(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) - summon[Converter[R]].convert(right)).toModInt
inline def *(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right)).toModInt
inline def /(right: R)(using inline mod: Int): ModInt = (summon[Converter[L]].convert(left) * summon[Converter[R]].convert(right).inverse
        ).toModInt
class Bit(size: Int):
import ModInt.*
private val vec = Array.fill(size){ModInt.zero}
inline def get(position: Int)(using inline mod: Int): ModInt =
var pos = position
var result = ModInt.zero
while 0 <= pos do
result += vec(pos)
pos -= ~pos & (pos + 1)
result
inline def add(position: Int, value: ModInt)(using inline mod: Int) =
var pos = position
while pos < size do
vec(pos) += value
pos += ~pos & (pos + 1)
@main def main =
inline given MOD: Int = 998244353
val n = readLine().toInt
val points = Array.fill(n){
val Array(x, y) = readLine().split(' ').map(_.toInt)
x -> y
}
val (startX, startY) = points.head
val (goalX, goalY) = points.last
val sx = if startX + startY <= goalX + goalY then 1 else -1
val sy = if startY - startX <= goalY - goalX then 1 else -1
val normalized = points.map{case (x, y) => (x + y - - startX - startY) * sx -> (y - x + startX - startY) * sy}
val yRank = normalized.map(_._2).distinct.sorted.zipWithIndex.toMap
val bit = Bit(yRank.size)
var result = ModInt.zero
for i <- normalized.indices.sorted(using Ordering.by[Int, Int](i => normalized(i)._1).orElseBy(i => normalized(i)._2)) do
val (_, y) = normalized(i)
if i == 0 then
bit.add(yRank(y), ModInt.one)
else if i == n - 1 then
result = bit.get(yRank(y))
else
val pattern = bit.get(yRank(y))
bit.add(yRank(y), pattern)
println(result.value)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0