結果

問題 No.1859 ><<<
ユーザー yudedakoyudedako
提出日時 2022-03-14 17:09:36
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,588 ms / 2,000 ms
コード長 1,663 bytes
コンパイル時間 16,205 ms
コンパイル使用メモリ 248,500 KB
実行使用メモリ 102,140 KB
最終ジャッジ日時 2023-10-20 08:53:10
合計ジャッジ時間 85,371 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 944 ms
65,680 KB
testcase_01 AC 940 ms
65,648 KB
testcase_02 AC 932 ms
65,644 KB
testcase_03 AC 950 ms
65,696 KB
testcase_04 AC 1,553 ms
102,056 KB
testcase_05 AC 1,588 ms
102,112 KB
testcase_06 AC 1,521 ms
102,140 KB
testcase_07 AC 1,550 ms
102,132 KB
testcase_08 AC 1,505 ms
102,112 KB
testcase_09 AC 1,545 ms
102,140 KB
testcase_10 AC 1,233 ms
70,224 KB
testcase_11 AC 1,465 ms
87,808 KB
testcase_12 AC 1,451 ms
85,404 KB
testcase_13 AC 1,332 ms
74,352 KB
testcase_14 AC 1,442 ms
87,172 KB
testcase_15 AC 1,477 ms
94,760 KB
testcase_16 AC 1,532 ms
97,808 KB
testcase_17 AC 1,461 ms
91,220 KB
testcase_18 AC 1,505 ms
97,616 KB
testcase_19 AC 1,472 ms
92,352 KB
testcase_20 AC 1,503 ms
97,000 KB
testcase_21 AC 1,531 ms
99,768 KB
testcase_22 AC 1,497 ms
99,216 KB
testcase_23 AC 1,501 ms
94,688 KB
testcase_24 AC 1,509 ms
99,516 KB
testcase_25 AC 1,497 ms
98,988 KB
testcase_26 AC 1,485 ms
97,076 KB
testcase_27 AC 1,511 ms
97,804 KB
testcase_28 AC 1,485 ms
97,432 KB
testcase_29 AC 1,496 ms
97,400 KB
testcase_30 AC 1,486 ms
94,672 KB
testcase_31 AC 1,490 ms
94,696 KB
testcase_32 AC 1,536 ms
99,604 KB
testcase_33 AC 1,547 ms
94,628 KB
testcase_34 AC 1,497 ms
97,536 KB
testcase_35 AC 1,518 ms
99,764 KB
testcase_36 AC 1,515 ms
99,656 KB
testcase_37 AC 1,496 ms
96,956 KB
testcase_38 AC 1,524 ms
99,900 KB
testcase_39 AC 1,532 ms
99,756 KB
testcase_40 AC 1,527 ms
99,440 KB
testcase_41 AC 1,504 ms
99,804 KB
testcase_42 AC 1,484 ms
94,580 KB
testcase_43 AC 1,535 ms
99,052 KB
testcase_44 AC 1,548 ms
97,032 KB
権限があれば一括ダウンロードができます

ソースコード

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


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)



0