結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-10-22 17:42:06 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,432 bytes |
コンパイル時間 | 1,865 ms |
コンパイル使用メモリ | 74,152 KB |
実行使用メモリ | 87,044 KB |
最終ジャッジ日時 | 2024-11-23 17:09:42 |
合計ジャッジ時間 | 54,133 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 13 TLE * 8 |
ソースコード
package yukicoder; 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(); //long start = System.currentTimeMillis(); //無理か判断 int m = 1; int distance = 0; int target; int muripo = 0; int count = 1; while (m != N) { count++; distance = 0; //System.out.println("----count:" + count); 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 (m == muripo) { System.out.println(-1); //long end = System.currentTimeMillis(); //System.out.println((end - start) + "ms"); return; } if (0 == muripo) { muripo = m; } } else { target = m + distance; } //System.out.println("target:" + target); //move m = target; //System.out.println("m:" + m); } //long end = System.currentTimeMillis(); //System.out.println((end - start) + "ms"); System.out.println(count); } }