結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-10-22 18:00:35 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,026 bytes |
コンパイル時間 | 2,500 ms |
コンパイル使用メモリ | 75,116 KB |
実行使用メモリ | 54,668 KB |
最終ジャッジ日時 | 2024-11-23 17:16:39 |
合計ジャッジ時間 | 8,846 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int m = 1; int distance = 0; int target; Map<Integer,Integer> muripo = new HashMap<>(); int count = 1; while (m != N) { count++; distance = 0; char[] c = Integer.toBinaryString(m).toCharArray(); for (int i = 0;i < c.length;i++) { if (c[i] == '1') { distance++; } } //get target if (N < m + distance) { target = m - distance; // 以前同じmで戻っている if (muripo.containsKey(m)) { System.out.println(-1); return; } muripo.put(m, m); } else { target = m + distance; } //move m = target; } System.out.println(count); } }