結果

問題 No.3 ビットすごろく
ユーザー holegumaholeguma
提出日時 2015-07-26 02:13:02
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 781 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 74,340 KB
実行使用メモリ 49,896 KB
最終ジャッジ日時 2023-09-22 23:17:53
合計ジャッジ時間 4,724 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,040 KB
testcase_01 AC 46 ms
49,108 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 47 ms
49,184 KB
testcase_05 WA -
testcase_06 AC 47 ms
49,540 KB
testcase_07 AC 47 ms
49,524 KB
testcase_08 AC 47 ms
49,236 KB
testcase_09 AC 46 ms
49,104 KB
testcase_10 WA -
testcase_11 AC 48 ms
49,224 KB
testcase_12 AC 48 ms
49,012 KB
testcase_13 WA -
testcase_14 AC 47 ms
49,300 KB
testcase_15 AC 48 ms
49,336 KB
testcase_16 AC 47 ms
49,200 KB
testcase_17 AC 48 ms
49,168 KB
testcase_18 AC 46 ms
49,320 KB
testcase_19 AC 46 ms
49,356 KB
testcase_20 AC 49 ms
49,048 KB
testcase_21 AC 47 ms
49,232 KB
testcase_22 WA -
testcase_23 AC 47 ms
49,216 KB
testcase_24 AC 49 ms
49,104 KB
testcase_25 AC 48 ms
49,224 KB
testcase_26 AC 47 ms
48,976 KB
testcase_27 AC 47 ms
49,192 KB
testcase_28 WA -
testcase_29 AC 49 ms
47,412 KB
testcase_30 AC 50 ms
49,096 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main{
final static int INF=Integer.MAX_VALUE/2;
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,INF);
Deque<Integer> que=new ArrayDeque<Integer>();
map[1]=1;
que.offerLast(1);
while(que.peekFirst()!=null){
int n=que.pollFirst();
int noo=Integer.bitCount(n);
if(n-noo>=1&&map[n-noo]>map[n]+1){
map[n-noo]=map[n]+1;
que.offerLast(n-noo);
}
if(n+noo<=10000&&map[n+noo]>map[n]+1){
map[n+noo]=map[n]+1;
que.offerLast(n+noo);
}
}
while((line=br.readLine())!=null){
int t=Integer.parseInt(line);
System.out.println(map[t]==INF?-1:map[t]);
}
}
}
0