結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-09-21 23:55:37 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,064 bytes |
コンパイル時間 | 3,386 ms |
コンパイル使用メモリ | 75,492 KB |
実行使用メモリ | 508,812 KB |
最終ジャッジ日時 | 2024-11-08 19:53:40 |
合計ジャッジ時間 | 113,552 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 RE * 32 |
ソースコード
package bitsgoroku; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Bitsugoroku { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); try { int result = 1; List<Integer> resultList = new ArrayList<Integer>(); resultList.add(result); int binCount = changeBinary(result); while (result + binCount != n) { if (result + binCount > n) {// nを超えてしまう時 result -= binCount; resultList.add(result); } else if (result + binCount < n) {// nを超えない時 result += binCount; resultList.add(result); } } System.out.println(resultList.size()); } catch (Exception e) { // TODO: handle exception } } private static int changeBinary(int result) { String bin = Integer.toBinaryString(result); String[] binArray = bin.split(""); // 2進数の1の数を数える int binCount = 0; for (String sss : binArray) { if (sss == "1") { binCount++; } } return binCount; } }