結果

問題 No.406 鴨等間隔の法則
ユーザー GoryudyumaGoryudyuma
提出日時 2018-04-13 12:33:30
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,737 ms / 2,000 ms
コード長 1,576 bytes
コンパイル時間 13,888 ms
コンパイル使用メモリ 260,812 KB
実行使用メモリ 73,328 KB
最終ジャッジ日時 2023-09-21 18:48:37
合計ジャッジ時間 62,958 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,456 ms
69,984 KB
testcase_01 AC 1,013 ms
63,196 KB
testcase_02 AC 1,011 ms
63,528 KB
testcase_03 AC 984 ms
63,524 KB
testcase_04 AC 1,603 ms
71,144 KB
testcase_05 AC 1,406 ms
67,092 KB
testcase_06 AC 1,445 ms
68,436 KB
testcase_07 AC 1,419 ms
67,244 KB
testcase_08 AC 1,535 ms
72,408 KB
testcase_09 AC 1,649 ms
72,388 KB
testcase_10 AC 1,436 ms
69,548 KB
testcase_11 AC 1,564 ms
71,856 KB
testcase_12 AC 1,466 ms
69,276 KB
testcase_13 AC 1,458 ms
66,384 KB
testcase_14 AC 1,661 ms
71,688 KB
testcase_15 AC 1,261 ms
66,604 KB
testcase_16 AC 1,327 ms
64,528 KB
testcase_17 AC 1,194 ms
64,852 KB
testcase_18 AC 1,287 ms
66,868 KB
testcase_19 AC 1,272 ms
66,896 KB
testcase_20 AC 1,339 ms
67,112 KB
testcase_21 AC 1,355 ms
67,556 KB
testcase_22 AC 1,392 ms
66,996 KB
testcase_23 AC 1,472 ms
69,380 KB
testcase_24 AC 1,617 ms
71,844 KB
testcase_25 AC 1,602 ms
70,976 KB
testcase_26 AC 1,718 ms
72,976 KB
testcase_27 AC 1,441 ms
66,692 KB
testcase_28 AC 1,534 ms
72,500 KB
testcase_29 AC 1,733 ms
72,944 KB
testcase_30 AC 1,737 ms
73,328 KB
testcase_31 AC 1,561 ms
71,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.{NumericRange, Queue}
import scala.collection.mutable
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val A = Array.fill(sc.nextInt)(sc.nextLong)
    println(if (A.toSet.size != A.size) ("NO") else {
      val B = A.sorted
      var flag = true
      for (i <- Range(1, B.size)) {
        if (B(1) - B(0) != B(i) - B(i - 1)) (flag = false)
      }
      if (flag) ("YES") else ("NO")
    })
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}
0