結果

問題 No.3 ビットすごろく
ユーザー holegumaholeguma
提出日時 2015-07-26 01:16:13
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 75,212 KB
実行使用メモリ 51,260 KB
最終ジャッジ日時 2023-09-22 23:15:46
合計ジャッジ時間 4,941 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 44 ms
49,184 KB
testcase_03 AC 44 ms
49,448 KB
testcase_04 WA -
testcase_05 AC 43 ms
49,296 KB
testcase_06 AC 42 ms
49,472 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 45 ms
49,120 KB
testcase_13 AC 44 ms
49,144 KB
testcase_14 AC 44 ms
49,592 KB
testcase_15 AC 44 ms
49,124 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 49 ms
49,208 KB
testcase_22 AC 48 ms
49,148 KB
testcase_23 AC 48 ms
49,296 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 44 ms
49,176 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Arrays;
import java.util.Deque;
import java.util.ArrayDeque;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int[] map=new int[10001];
Arrays.fill(map,-1);
Deque<Integer> que=new ArrayDeque<Integer>();
map[1]=1;
que.offerLast(1);
if(que.peekFirst()!=null){
int n=que.pollFirst();
if(n+numOfOne(n)<=10000&&map[n+numOfOne(n)]==-1){
map[n+numOfOne(n)]=map[n]+1;
que.offerLast(n+numOfOne(n));
}
if(n-numOfOne(n)>=1&&map[n-numOfOne(n)]==-1){
map[n-numOfOne(n)]=map[n]+1;
que.offerLast(n-numOfOne(n));
}
}
while((line=br.readLine())!=null){
int t=Integer.parseInt(line);
System.out.println(map[t]);
}
}
private static int numOfOne(int n){
int count=0;
String val2=Integer.toBinaryString(n);
for(int i=0;i<val2.length();i++){
if(val2.charAt(i)=='1'){
count++;
}
}
return count;
}
}
0