結果

問題 No.3 ビットすごろく
ユーザー koba-e964koba-e964
提出日時 2015-12-09 02:57:07
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,119 ms / 5,000 ms
コード長 755 bytes
コンパイル時間 12,097 ms
コンパイル使用メモリ 254,520 KB
実行使用メモリ 63,836 KB
最終ジャッジ日時 2023-09-13 23:37:41
合計ジャッジ時間 49,595 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,066 ms
63,252 KB
testcase_01 AC 1,066 ms
63,268 KB
testcase_02 AC 1,055 ms
63,352 KB
testcase_03 AC 1,089 ms
63,568 KB
testcase_04 AC 1,067 ms
63,468 KB
testcase_05 AC 1,117 ms
63,716 KB
testcase_06 AC 1,070 ms
63,408 KB
testcase_07 AC 1,068 ms
63,388 KB
testcase_08 AC 1,063 ms
63,628 KB
testcase_09 AC 1,063 ms
63,644 KB
testcase_10 AC 1,076 ms
63,476 KB
testcase_11 AC 1,069 ms
63,552 KB
testcase_12 AC 1,066 ms
63,620 KB
testcase_13 AC 1,044 ms
63,836 KB
testcase_14 AC 1,109 ms
63,348 KB
testcase_15 AC 1,078 ms
63,620 KB
testcase_16 AC 1,073 ms
63,676 KB
testcase_17 AC 1,119 ms
63,564 KB
testcase_18 AC 1,065 ms
63,416 KB
testcase_19 AC 1,082 ms
63,440 KB
testcase_20 AC 1,047 ms
63,476 KB
testcase_21 AC 1,027 ms
63,540 KB
testcase_22 AC 1,061 ms
63,492 KB
testcase_23 AC 1,055 ms
63,364 KB
testcase_24 AC 1,068 ms
63,416 KB
testcase_25 AC 1,059 ms
63,608 KB
testcase_26 AC 1,010 ms
63,360 KB
testcase_27 AC 1,038 ms
63,444 KB
testcase_28 AC 1,061 ms
63,344 KB
testcase_29 AC 1,053 ms
63,836 KB
testcase_30 AC 1,014 ms
63,504 KB
testcase_31 AC 1,025 ms
63,352 KB
testcase_32 AC 1,063 ms
63,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * Reference: http://lizan.asia/blog/2012/12/11/scala-competitive/
 */

object Main extends App {
  import java.{util => ju}
  import scala.annotation._
  import scala.collection._
  import scala.collection.{mutable => mu}
  import scala.collection.JavaConverters._
  import scala.math._

  val sc = new ju.Scanner(System.in)

  val n = sc.nextInt
  val que = new mu.Queue[(Int, Int)]
  val inf = 0x3fffffff
  val dist = Array.fill(n + 1)(inf)
  que += 0 -> 1
  while (que.nonEmpty) {
    val (d, t) = que.dequeue
    if (d < dist(t)) {
      dist(t) = d
      val bc = Integer.bitCount(t)
      if (t - bc >= 1) que += (d + 1) -> (t - bc)
      if (t + bc <= n) que += (d + 1) -> (t + bc)
    }
  }
  println(if (dist(n) == inf) -1 else dist(n) + 1)
}
0