結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-01-20 12:38:42 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,134 bytes |
コンパイル時間 | 2,252 ms |
コンパイル使用メモリ | 78,740 KB |
実行使用メモリ | 42,896 KB |
最終ジャッジ日時 | 2024-09-21 14:44:56 |
合計ジャッジ時間 | 6,284 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; public class Main { public static void main(String[] args) { BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in)); try { int N = Integer.parseInt(stdReader.readLine()); int[] c = new int[N+1]; for(int i=1;i<N+1;i++){ int count = 0; String bin = Integer.toBinaryString(i); for(int j=0;j<bin.length();j++){ if((""+bin.charAt(j)).equals("1")) count++; } c[i] = count; } int result = 1; int here = 1; HashMap<Integer , String> hMap = new HashMap<>(); while(here<N){ if(hMap.containsKey(here)){ result = -1; break; }else{ hMap.put(here, ""); } if(here + c[here]<=N) here += c[here]; else if(here + c[here]>N) here -= c[here]; result++; } System.out.println(result); } catch (IOException e) { e.printStackTrace(); } } }