結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2016-12-15 15:13:54 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,087 bytes |
コンパイル時間 | 2,275 ms |
コンパイル使用メモリ | 74,816 KB |
実行使用メモリ | 56,308 KB |
最終ジャッジ日時 | 2024-11-30 08:23:35 |
合計ジャッジ時間 | 8,914 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 WA * 22 |
ソースコード
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int goal = sc.nextInt(); sc.close(); int moveCount = 1; int currentPos = 1; List<Integer> moveHistory = new ArrayList<Integer>(); while (true) { if (goal == currentPos) { break; } if (moveHistory.contains(currentPos)) { moveCount = -1; break; } moveHistory.add(currentPos); // dice! int dice = int2bit1count(currentPos); if (goal > currentPos + dice) { currentPos += dice; } else { currentPos -= dice; } moveCount++; } System.out.println(moveCount); } public static int int2bit1count(Integer num) { String bitStr = Integer.toBinaryString(num); return bitStr.replace("0", "").length(); } }