結果
問題 | No.3 ビットすごろく |
ユーザー | scaler |
提出日時 | 2024-08-31 11:30:25 |
言語 | Scala(Beta) (3.4.0) |
結果 |
AC
|
実行時間 | 958 ms / 5,000 ms |
コード長 | 728 bytes |
コンパイル時間 | 12,866 ms |
コンパイル使用メモリ | 267,000 KB |
実行使用メモリ | 65,400 KB |
最終ジャッジ日時 | 2024-08-31 11:31:12 |
合計ジャッジ時間 | 41,508 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 912 ms
64,948 KB |
testcase_01 | AC | 912 ms
64,960 KB |
testcase_02 | AC | 894 ms
65,212 KB |
testcase_03 | AC | 917 ms
65,348 KB |
testcase_04 | AC | 927 ms
65,344 KB |
testcase_05 | AC | 885 ms
65,088 KB |
testcase_06 | AC | 902 ms
65,240 KB |
testcase_07 | AC | 913 ms
65,124 KB |
testcase_08 | AC | 929 ms
65,180 KB |
testcase_09 | AC | 906 ms
65,096 KB |
testcase_10 | AC | 925 ms
65,292 KB |
testcase_11 | AC | 920 ms
65,308 KB |
testcase_12 | AC | 909 ms
65,152 KB |
testcase_13 | AC | 880 ms
65,332 KB |
testcase_14 | AC | 929 ms
65,208 KB |
testcase_15 | AC | 936 ms
65,312 KB |
testcase_16 | AC | 930 ms
65,240 KB |
testcase_17 | AC | 900 ms
65,188 KB |
testcase_18 | AC | 908 ms
64,960 KB |
testcase_19 | AC | 958 ms
65,140 KB |
testcase_20 | AC | 923 ms
65,120 KB |
testcase_21 | AC | 894 ms
65,272 KB |
testcase_22 | AC | 935 ms
65,136 KB |
testcase_23 | AC | 935 ms
65,196 KB |
testcase_24 | AC | 935 ms
65,400 KB |
testcase_25 | AC | 911 ms
65,308 KB |
testcase_26 | AC | 896 ms
65,056 KB |
testcase_27 | AC | 918 ms
65,052 KB |
testcase_28 | AC | 918 ms
65,080 KB |
testcase_29 | AC | 895 ms
65,244 KB |
testcase_30 | AC | 912 ms
65,184 KB |
testcase_31 | AC | 915 ms
65,240 KB |
testcase_32 | AC | 904 ms
65,172 KB |
ソースコード
import scala.io.StdIn.readLine import scala.collection.mutable.Queue @main def yuki3(): Unit = val N = readLine().split(" ").map(_.toInt).head val dist: Array[Int] = Array.ofDim[Int](10001) val visited: Array[Boolean] = Array.ofDim[Boolean](10001) var q = Queue[Int](1) visited(1) = true while q.nonEmpty do val x = q.dequeue var p = 0 var num = x while num != 0 do p += num & 1 num >>= 1 if x + p <= N && !visited(x + p) then visited(x + p) = true dist(x + p) = dist(x) + 1 q.enqueue(x + p) if x - p > 0 && !visited(x - p) then visited(x - p) = true dist(x - p) = dist(x) + 1 q.enqueue(x - p) println(if visited(N) then dist(N) + 1 else -1)