結果
問題 | No.1859 ><<< |
ユーザー | yudedako |
提出日時 | 2022-03-14 17:09:36 |
言語 | Scala(Beta) (3.4.0) |
結果 |
AC
|
実行時間 | 1,537 ms / 2,000 ms |
コード長 | 1,663 bytes |
コンパイル時間 | 11,783 ms |
コンパイル使用メモリ | 273,328 KB |
実行使用メモリ | 100,348 KB |
最終ジャッジ日時 | 2024-09-20 04:23:20 |
合計ジャッジ時間 | 79,038 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 874 ms
63,468 KB |
testcase_01 | AC | 882 ms
63,704 KB |
testcase_02 | AC | 905 ms
63,604 KB |
testcase_03 | AC | 893 ms
63,716 KB |
testcase_04 | AC | 1,537 ms
100,320 KB |
testcase_05 | AC | 1,478 ms
100,348 KB |
testcase_06 | AC | 1,446 ms
100,176 KB |
testcase_07 | AC | 1,447 ms
99,868 KB |
testcase_08 | AC | 1,466 ms
99,928 KB |
testcase_09 | AC | 1,517 ms
99,732 KB |
testcase_10 | AC | 1,172 ms
68,396 KB |
testcase_11 | AC | 1,387 ms
86,936 KB |
testcase_12 | AC | 1,365 ms
83,256 KB |
testcase_13 | AC | 1,263 ms
74,196 KB |
testcase_14 | AC | 1,366 ms
86,660 KB |
testcase_15 | AC | 1,418 ms
94,152 KB |
testcase_16 | AC | 1,443 ms
96,396 KB |
testcase_17 | AC | 1,392 ms
88,948 KB |
testcase_18 | AC | 1,449 ms
96,136 KB |
testcase_19 | AC | 1,480 ms
91,264 KB |
testcase_20 | AC | 1,434 ms
95,116 KB |
testcase_21 | AC | 1,476 ms
99,376 KB |
testcase_22 | AC | 1,415 ms
97,512 KB |
testcase_23 | AC | 1,409 ms
93,844 KB |
testcase_24 | AC | 1,412 ms
98,676 KB |
testcase_25 | AC | 1,398 ms
96,908 KB |
testcase_26 | AC | 1,397 ms
95,192 KB |
testcase_27 | AC | 1,423 ms
96,464 KB |
testcase_28 | AC | 1,405 ms
95,664 KB |
testcase_29 | AC | 1,404 ms
95,720 KB |
testcase_30 | AC | 1,412 ms
94,200 KB |
testcase_31 | AC | 1,410 ms
94,068 KB |
testcase_32 | AC | 1,436 ms
99,072 KB |
testcase_33 | AC | 1,432 ms
93,908 KB |
testcase_34 | AC | 1,380 ms
95,732 KB |
testcase_35 | AC | 1,402 ms
99,556 KB |
testcase_36 | AC | 1,418 ms
99,136 KB |
testcase_37 | AC | 1,403 ms
94,764 KB |
testcase_38 | AC | 1,478 ms
99,616 KB |
testcase_39 | AC | 1,489 ms
99,572 KB |
testcase_40 | AC | 1,436 ms
95,812 KB |
testcase_41 | AC | 1,419 ms
99,224 KB |
testcase_42 | AC | 1,430 ms
93,608 KB |
testcase_43 | AC | 1,433 ms
94,828 KB |
testcase_44 | AC | 1,400 ms
95,372 KB |
ソースコード
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 def powMod(base: Long, exp: Int, mod: Int): Long = var result = 1L var b = base % mod var e = exp while e > 0 do if (e & 1) == 1 then result = result * b % mod b = b * b % mod e >>= 1 result @main def main() = inline val MOD = 1_000_000_007 val random = Random(0) val n = readLine().toInt val num = readLine().split(' ').map(_.toInt) val str = readLine() val isMatch = Array.fill(2 * n - 1){true} val double = (num ++ num).pipe{array => (1 until array.length).map{i => if array(i - 1) < array(i) then 0 else 1}.toArray } val target = str.map{ case '<' => 0 case '>' => 1 }.toArray val left = powMod(2, n - 1, MOD) for _ <- 0 until 3 do val x = random.nextInt(MOD) val targetHash = target.foldLeft(0L){ (acc, v) => ((acc << 1) + v * x) % MOD} var hash = target.indices.foldLeft(0L){ (acc, i) => ((acc << 1) + double(i) * x) % MOD} isMatch(target.length - 1) = hash == targetHash //println(s"$hash, $targetHash") for i <- target.length until double.length do hash = ((hash << 1) + double(i) * x) % MOD hash = (hash - left * double(i - target.length) * x % MOD + MOD) % MOD isMatch(i) = isMatch(i) && hash == targetHash //println(s"$hash, $targetHash") (target.length - 1 until isMatch.length).find(isMatch(_)) match case Some(i) => println(i - target.length + 1) case None => println(-1)