結果

問題 No.1779 Magical Swap
ユーザー yudedakoyudedako
提出日時 2022-02-02 13:28:25
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,552 ms / 2,000 ms
コード長 1,208 bytes
コンパイル時間 12,620 ms
コンパイル使用メモリ 251,084 KB
実行使用メモリ 78,560 KB
最終ジャッジ日時 2023-09-02 02:43:21
合計ジャッジ時間 39,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 975 ms
62,644 KB
testcase_01 AC 993 ms
62,788 KB
testcase_02 AC 1,283 ms
72,984 KB
testcase_03 AC 999 ms
62,740 KB
testcase_04 AC 1,502 ms
77,752 KB
testcase_05 AC 1,287 ms
65,436 KB
testcase_06 AC 1,361 ms
68,640 KB
testcase_07 AC 1,469 ms
78,560 KB
testcase_08 AC 1,020 ms
62,860 KB
testcase_09 AC 1,292 ms
64,096 KB
testcase_10 AC 1,518 ms
77,344 KB
testcase_11 AC 1,335 ms
68,460 KB
testcase_12 AC 1,238 ms
64,300 KB
testcase_13 AC 1,482 ms
75,240 KB
testcase_14 AC 1,552 ms
77,512 KB
testcase_15 AC 1,344 ms
73,284 KB
testcase_16 AC 1,374 ms
78,548 KB
testcase_17 AC 1,372 ms
64,844 KB
testcase_18 AC 967 ms
63,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn.*
import scala.util.chaining.*
import scala.math.*

def calcPrime(upperLimit: Int): Array[Int] =
  val isPrime = Array.fill(upperLimit + 1){true}
  for p <- 2 to sqrt(upperLimit).toInt do
    if isPrime(p) then
      for j <- p * p to upperLimit by p do
        isPrime(j) = false
  (2 to upperLimit).filter(isPrime).toArray

extension (array: Array[Int])
  def upperBound(value: Int): Int =
    var min = 0
    var max = array.length
    while min < max do
      val mid = (min + max) >>> 1
      if array(mid) <= value then
        min = mid + 1
      else
        max = mid
    max

@main def main =
  val prime = calcPrime(100000)
  val testCase = readLine().toInt
  val isOk = Array.fill(testCase){false}
  for t <- 0 until testCase do
    val n = readLine().toInt
    val a = readLine().split(' ').map(_.toInt)
    val b = readLine().split(' ').map(_.toInt)
    if a.sorted sameElements b.sorted then
      isOk(t) = a(0) == b(0) && (prime.upperBound(n / 2) until prime.upperBound(n)).forall(i => a(prime(i) - 1) == b(prime(i) - 1))
  println(
    isOk.map(if _ then "Yes" else "No").mkString("\n")
  )
0