結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2019-05-19 23:56:48 |
言語 | Scala(Beta) (3.6.2) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,016 bytes |
コンパイル時間 | 10,497 ms |
コンパイル使用メモリ | 269,460 KB |
実行使用メモリ | 78,368 KB |
最終ジャッジ日時 | 2024-07-02 01:36:09 |
合計ジャッジ時間 | 34,414 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 TLE * 1 -- * 22 |
ソースコード
import java.util import scala.collection.mutable object Main { def main(args: Array[String]): Unit = { 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.poll() if (p.now == i) { ans += p } else if (1 <= p.now && p.now <= i) { val newPoint: Int = p.now.toBinaryString.replaceAll("0", "").length if (!p.history(p.now + newPoint)) { queue.add(Point(p.count + 1, p.now + newPoint, p.history += p.now)) } if (!p.history(p.now - newPoint)) { queue.add(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])