結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 40 ms
49,268 KB
testcase_03 AC 40 ms
47,132 KB
testcase_04 WA -
testcase_05 AC 40 ms
49,460 KB
testcase_06 AC 39 ms
49,224 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 40 ms
49,608 KB
testcase_13 AC 40 ms
49,444 KB
testcase_14 AC 40 ms
49,108 KB
testcase_15 AC 40 ms
49,652 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 39 ms
49,128 KB
testcase_22 AC 40 ms
49,100 KB
testcase_23 AC 40 ms
49,160 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 39 ms
49,148 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{
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);
if(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