結果

問題 No.3 ビットすごろく
ユーザー sakuraigakusakuraigaku
提出日時 2019-05-20 00:15:48
言語 Scala(Beta)
(3.3.1)
結果
WA  
実行時間 -
コード長 1,253 bytes
コンパイル時間 11,209 ms
コンパイル使用メモリ 255,304 KB
実行使用メモリ 65,380 KB
最終ジャッジ日時 2023-09-14 18:35:12
合計ジャッジ時間 49,807 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,012 ms
63,736 KB
testcase_01 AC 1,001 ms
64,072 KB
testcase_02 AC 979 ms
63,876 KB
testcase_03 AC 1,086 ms
63,852 KB
testcase_04 WA -
testcase_05 AC 1,124 ms
63,748 KB
testcase_06 AC 1,112 ms
63,764 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1,167 ms
63,768 KB
testcase_13 AC 1,105 ms
63,808 KB
testcase_14 AC 1,225 ms
63,932 KB
testcase_15 AC 1,234 ms
63,976 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 989 ms
63,760 KB
testcase_22 AC 1,228 ms
64,572 KB
testcase_23 AC 1,239 ms
63,908 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 990 ms
63,488 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util
import scala.collection.mutable


object Main {

  def main(args: Array[String]): Unit = {

    var minCount: Int = 0
//    def min(count: Int): Boolean = {
//      if (minCount == 0) {
//        true
//      }else if(count>minCount){
//        false
//      }else{
//        true
//      }
//    }

    val sc = new java.util.Scanner(System.in)
    val i: Int = sc.nextInt()

    val queue = new util.ArrayDeque[Point]()
    val ans: mutable.Set[Point] = mutable.Set[Point]()

    queue.add(Point(1, 1, mutable.Set(1)))
    while (!queue.isEmpty) {
      val p = queue.pop()
      if (p.now == i) {
        ans += p
        minCount = p.count
      } else if (1 <= p.now && p.now <= i ) {
        val newPoint: Int = p.now.toBinaryString.replaceAll("0", "").length
        if (!p.history(p.now + newPoint)) {
          queue.push(Point(p.count + 1, p.now + newPoint, p.history += p.now))
        }
        if (!p.history(p.now - newPoint)) {
          queue.push(Point(p.count + 1, p.now - newPoint, p.history += p.now))
        }
      }
    }

    if (ans.isEmpty) {
      printf("-1")
    } else {
      printf(ans.seq.map(p => p.count).min.toString)
    }

  }

}

case class Point(count: Int, now: Int, history: mutable.Set[Int])
0