結果

問題 No.648  お や す み 
ユーザー GoryudyumaGoryudyuma
提出日時 2018-05-02 18:42:32
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 1,763 bytes
コンパイル時間 9,200 ms
コンパイル使用メモリ 254,776 KB
実行使用メモリ 63,956 KB
最終ジャッジ日時 2023-09-12 18:55:20
合計ジャッジ時間 95,709 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 962 ms
62,556 KB
testcase_01 AC 973 ms
62,604 KB
testcase_02 AC 969 ms
62,356 KB
testcase_03 AC 965 ms
62,360 KB
testcase_04 AC 968 ms
62,332 KB
testcase_05 AC 959 ms
62,344 KB
testcase_06 AC 967 ms
62,384 KB
testcase_07 AC 962 ms
62,700 KB
testcase_08 AC 968 ms
62,356 KB
testcase_09 AC 970 ms
62,540 KB
testcase_10 AC 970 ms
62,412 KB
testcase_11 AC 959 ms
62,448 KB
testcase_12 AC 951 ms
62,392 KB
testcase_13 AC 961 ms
62,464 KB
testcase_14 AC 974 ms
62,760 KB
testcase_15 AC 971 ms
62,244 KB
testcase_16 AC 965 ms
62,404 KB
testcase_17 AC 960 ms
62,504 KB
testcase_18 AC 961 ms
62,292 KB
testcase_19 AC 948 ms
62,484 KB
testcase_20 AC 956 ms
62,284 KB
testcase_21 AC 960 ms
62,472 KB
testcase_22 AC 957 ms
62,532 KB
testcase_23 AC 969 ms
62,508 KB
testcase_24 AC 963 ms
62,364 KB
testcase_25 AC 953 ms
62,332 KB
testcase_26 AC 961 ms
62,416 KB
testcase_27 AC 964 ms
62,636 KB
testcase_28 AC 961 ms
62,568 KB
testcase_29 AC 969 ms
62,468 KB
testcase_30 AC 967 ms
62,444 KB
testcase_31 AC 968 ms
62,304 KB
testcase_32 AC 965 ms
62,400 KB
testcase_33 AC 962 ms
62,372 KB
testcase_34 AC 967 ms
62,396 KB
testcase_35 AC 969 ms
62,616 KB
testcase_36 AC 966 ms
62,460 KB
testcase_37 AC 967 ms
62,408 KB
testcase_38 AC 972 ms
62,332 KB
testcase_39 AC 967 ms
62,828 KB
testcase_40 AC 960 ms
62,464 KB
testcase_41 AC 962 ms
62,616 KB
testcase_42 AC 965 ms
62,336 KB
testcase_43 AC 972 ms
62,304 KB
testcase_44 AC 964 ms
62,596 KB
testcase_45 AC 968 ms
62,296 KB
testcase_46 AC 958 ms
62,288 KB
testcase_47 AC 965 ms
62,568 KB
testcase_48 AC 968 ms
62,448 KB
testcase_49 AC 964 ms
62,564 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 973 ms
62,556 KB
testcase_61 AC 966 ms
62,544 KB
testcase_62 AC 972 ms
62,580 KB
testcase_63 AC 965 ms
62,524 KB
testcase_64 AC 975 ms
62,456 KB
testcase_65 AC 962 ms
62,412 KB
testcase_66 AC 969 ms
62,280 KB
testcase_67 AC 982 ms
62,300 KB
testcase_68 AC 958 ms
62,484 KB
testcase_69 AC 965 ms
62,312 KB
testcase_70 AC 972 ms
62,432 KB
testcase_71 AC 974 ms
62,628 KB
testcase_72 AC 969 ms
62,404 KB
testcase_73 AC 964 ms
62,584 KB
testcase_74 AC 956 ms
62,384 KB
testcase_75 AC 963 ms
62,376 KB
testcase_76 AC 968 ms
62,472 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 969 ms
62,280 KB
testcase_83 AC 962 ms
62,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
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 N = sc.nextLong
    val ans = solve2(0, 1L << 60, N)
    if (ans._1) {
      println("YES")
      println(ans._2)
    } else {
      println("NO")
    }
  }

  def solve2(minV: Long, maxV: Long, N: Long): (Boolean, Long) = {
    if (minV + 2 > maxV) {
      (calc(minV) == N, minV)
    } else {
      val midV = (minV + maxV) / 2
      if (calc(midV) <= N) {
        solve2(midV, maxV, N)
      } else {
        solve2(minV, midV, N)
      }
    }
  }

  def calc(v: Long): Long = (v + 1) * v / 2

  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