結果
問題 | No.1845 Long Substrings |
ユーザー | yudedako |
提出日時 | 2022-02-28 21:43:41 |
言語 | Scala(Beta) (3.4.0) |
結果 |
AC
|
実行時間 | 1,448 ms / 2,000 ms |
コード長 | 3,893 bytes |
コンパイル時間 | 15,532 ms |
コンパイル使用メモリ | 266,264 KB |
実行使用メモリ | 97,448 KB |
最終ジャッジ日時 | 2023-09-21 06:32:25 |
合計ジャッジ時間 | 60,534 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,393 ms
85,684 KB |
testcase_01 | AC | 1,380 ms
97,248 KB |
testcase_02 | AC | 1,392 ms
85,492 KB |
testcase_03 | AC | 1,402 ms
85,256 KB |
testcase_04 | AC | 1,403 ms
97,084 KB |
testcase_05 | AC | 1,393 ms
83,472 KB |
testcase_06 | AC | 1,448 ms
84,416 KB |
testcase_07 | AC | 1,393 ms
97,448 KB |
testcase_08 | AC | 1,395 ms
83,800 KB |
testcase_09 | AC | 1,406 ms
84,512 KB |
testcase_10 | AC | 1,393 ms
93,140 KB |
testcase_11 | AC | 1,384 ms
83,696 KB |
testcase_12 | AC | 1,390 ms
83,052 KB |
testcase_13 | AC | 1,379 ms
85,960 KB |
testcase_14 | AC | 1,404 ms
85,276 KB |
testcase_15 | AC | 999 ms
63,084 KB |
testcase_16 | AC | 993 ms
62,632 KB |
testcase_17 | AC | 999 ms
62,848 KB |
testcase_18 | AC | 1,003 ms
62,828 KB |
testcase_19 | AC | 1,011 ms
62,544 KB |
testcase_20 | AC | 958 ms
62,400 KB |
testcase_21 | AC | 953 ms
62,392 KB |
testcase_22 | AC | 944 ms
62,564 KB |
testcase_23 | AC | 942 ms
62,428 KB |
testcase_24 | AC | 949 ms
62,408 KB |
testcase_25 | AC | 945 ms
62,428 KB |
testcase_26 | AC | 948 ms
62,404 KB |
testcase_27 | AC | 937 ms
62,532 KB |
testcase_28 | AC | 941 ms
62,332 KB |
testcase_29 | AC | 946 ms
62,300 KB |
testcase_30 | AC | 950 ms
62,392 KB |
testcase_31 | AC | 940 ms
61,896 KB |
testcase_32 | AC | 932 ms
62,364 KB |
testcase_33 | AC | 947 ms
62,312 KB |
ソースコード
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 toLong(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 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)).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 import ModInt.* inline given mod: Int = 1000000007 class Bit(size: Int): private val vec = Array.fill(size){zero} inline def get(position: Int)(using inline mod: Int): ModInt = var pos = position var result = zero while pos >= 0 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) inline def getAll(using inline mod: Int): ModInt = get(size - 1) @main def main = val n = readLine.toInt val length = readLine.split(' ').map(_.toInt) val str = readLine val prev = Array.fill(n + 1){-1} val lastPosition = Array.fill(26){0} for (c, i) <- str.zipWithIndex do prev(i + 1) = lastPosition(c - 'a') lastPosition(c - 'a') = i + 1 val useAll = Array.fill(n + 1){zero}.tap(_(0) = one) val allPattern = Bit(n + 1).tap(_.add(0, one)) for i <- 1 to n do val len = length(i - 1) val p = prev(i) val unique = allPattern.get(i) - allPattern.get(p) val expand = useAll(p) val newPattern = (unique + expand) * len useAll(i) = unique + expand allPattern.add(i, newPattern) println((allPattern.getAll - 1).toLong)