結果

問題 No.3 ビットすごろく
ユーザー holegumaholeguma
提出日時 2015-07-26 01:29:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 923 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 74,004 KB
実行使用メモリ 51,272 KB
最終ジャッジ日時 2023-09-22 23:16:32
合計ジャッジ時間 4,522 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 39 ms
49,316 KB
testcase_03 AC 39 ms
49,284 KB
testcase_04 WA -
testcase_05 AC 40 ms
49,236 KB
testcase_06 AC 41 ms
49,156 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 40 ms
49,364 KB
testcase_13 AC 39 ms
49,100 KB
testcase_14 AC 40 ms
49,156 KB
testcase_15 AC 40 ms
49,268 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 40 ms
49,308 KB
testcase_22 AC 41 ms
49,228 KB
testcase_23 AC 41 ms
49,268 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 41 ms
49,272 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.offerFirst(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.offerFirst(n+numOfOne(n));
}
if(n-numOfOne(n)>1&&map[n-numOfOne(n)]==-1){
map[n-numOfOne(n)]=map[n]+1;
que.offerFirst(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