結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-11-05 20:41:06 | 
| 言語 | Scala(Beta) (3.6.2) | 
| 結果 | 
                                CE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 958 bytes | 
| コンパイル時間 | 6,003 ms | 
| コンパイル使用メモリ | 223,444 KB | 
| 最終ジャッジ日時 | 2024-11-14 19:25:27 | 
| 合計ジャッジ時間 | 6,356 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
            
            
            
            
            ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
[31m[31m-- [E040] Syntax Error: Main.scala:40:32 ---------------------------------------[0m[0m
[31m40 |[0m  [33mdef[0m [36mmain[0m([36margs[0m: [35mArray[0m[[35mString[0m]) {
[31m[31m   |[0m                                ^[0m
[31m   |[0m                                '=' expected, but '{' found
1 error found
            
            ソースコード
import scala.collection.mutable
import scala.io.StdIn
object Problem003 {
  def bitCount(i: Int): Int = Integer.bitCount(i)
  def proc(goal: Int): Int = {
    def inField(i: Int): Boolean = 1 <= i && i <= goal
    val dp = Array.fill(goal + 1)(Int.MaxValue)
    dp(1) = 0
    val queue = new mutable.Queue[Int]()
    queue += 1
    while (queue.nonEmpty) {
      def enqueue(currentPlace: Int, nextSteps: Int): Unit = {
        if (inField(currentPlace) && dp(currentPlace) > nextSteps) {
          queue += currentPlace
          dp(currentPlace) = nextSteps
        }
      }
      val s = queue.dequeue()
      if (s == goal) return dp(goal) + 1
      val back = s - bitCount(s)
      val forward = s + bitCount(s)
      val nextSteps = dp(s) + 1
      enqueue(back, nextSteps)
      enqueue(forward, nextSteps)
    }
    -1
  }
  def main(args: Array[String]) {
    val n = StdIn.readInt()
    val result = proc(n)
    println(result)
  }
}
            
            
            
        