結果

問題 No.1880 Many Ways
ユーザー yudedakoyudedako
提出日時 2022-04-18 18:33:40
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 964 ms / 2,000 ms
コード長 1,569 bytes
コンパイル時間 8,659 ms
コンパイル使用メモリ 260,048 KB
実行使用メモリ 63,532 KB
最終ジャッジ日時 2023-08-28 14:53:20
合計ジャッジ時間 35,596 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 859 ms
61,276 KB
testcase_01 AC 854 ms
61,284 KB
testcase_02 AC 871 ms
61,300 KB
testcase_03 AC 943 ms
62,956 KB
testcase_04 AC 952 ms
62,564 KB
testcase_05 AC 947 ms
63,212 KB
testcase_06 AC 946 ms
62,944 KB
testcase_07 AC 949 ms
62,880 KB
testcase_08 AC 964 ms
63,352 KB
testcase_09 AC 953 ms
63,124 KB
testcase_10 AC 955 ms
62,980 KB
testcase_11 AC 958 ms
63,276 KB
testcase_12 AC 956 ms
63,112 KB
testcase_13 AC 955 ms
63,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
import scala.language.strictEquality



@main def main =
  val a = readLine.toLong
  if a == 0L then
    println("2 0")
  else if a == 1L then
    println("2 1")
    println("1 2")
  else if a == 2L then
    println("4 4")
    println("1 2")
    println("1 3")
    println("2 4")
    println("3 4")
  else
    val maxLength = (a - 1).toBinaryString
    val edges = mutable.Set[(Int, Int)]()
    val nodes = mutable.ArrayDeque[Int]().addAll(1 to 128)
    val start = nodes.removeHead()
    val single = Array.fill(maxLength.length){nodes.removeHead()}
    val double = Array.fill(maxLength.length - 1){Array.fill(2){nodes.removeHead()}}
    val branch = nodes.removeHead()
    val goal = nodes.removeHead()
    edges.add(start -> single(0))
    for i <- 1 until single.length do
      edges.add(single(i - 1) -> single(i))
    edges.add(single.last -> goal)
    for v <- double(0) do
      edges.add(start -> v)
    for
      i <- 1 until double.length
      v <- double(i - 1)
      u <- double(i)
    do
      edges.add(v -> u)
    for v <- double.last do
      edges.add(v -> branch)
    edges.add(branch -> goal)
    val rest = a - 1
    for i <- double.indices do
      if (rest >> i) % 2 == 1L then
        edges.add(double(i)(0) -> single(i + 1))
    println(s"$goal ${edges.size}")
    println(edges.map((u, v) => s"$u $v").mkString("\n"))
0