結果

問題 No.3 ビットすごろく
ユーザー holegumaholeguma
提出日時 2015-07-26 02:17:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 775 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 74,324 KB
実行使用メモリ 51,324 KB
最終ジャッジ日時 2023-09-13 23:17:11
合計ジャッジ時間 5,053 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,688 KB
testcase_01 AC 44 ms
49,320 KB
testcase_02 AC 45 ms
51,324 KB
testcase_03 AC 47 ms
49,320 KB
testcase_04 AC 46 ms
49,348 KB
testcase_05 AC 48 ms
49,224 KB
testcase_06 AC 47 ms
49,296 KB
testcase_07 AC 47 ms
49,204 KB
testcase_08 AC 48 ms
49,352 KB
testcase_09 AC 50 ms
49,624 KB
testcase_10 AC 50 ms
49,308 KB
testcase_11 AC 49 ms
49,524 KB
testcase_12 AC 48 ms
49,360 KB
testcase_13 AC 47 ms
49,340 KB
testcase_14 AC 49 ms
49,300 KB
testcase_15 AC 51 ms
49,216 KB
testcase_16 AC 51 ms
49,404 KB
testcase_17 AC 52 ms
49,664 KB
testcase_18 AC 48 ms
49,284 KB
testcase_19 AC 51 ms
49,180 KB
testcase_20 AC 44 ms
49,180 KB
testcase_21 AC 44 ms
49,348 KB
testcase_22 AC 50 ms
49,396 KB
testcase_23 AC 52 ms
49,624 KB
testcase_24 AC 52 ms
49,288 KB
testcase_25 AC 51 ms
49,420 KB
testcase_26 AC 44 ms
49,152 KB
testcase_27 AC 48 ms
49,320 KB
testcase_28 AC 51 ms
49,160 KB
testcase_29 AC 50 ms
49,220 KB
testcase_30 AC 43 ms
49,172 KB
testcase_31 AC 44 ms
49,388 KB
testcase_32 AC 50 ms
50,316 KB
権限があれば一括ダウンロードができます

ソースコード

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="";
while((line=br.readLine())!=null){
int t=Integer.parseInt(line);
int[] map=new int[t+1];
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<=t&&map[n+noo]>map[n]+1){
map[n+noo]=map[n]+1;
que.offerLast(n+noo);
}
}
System.out.println(map[t]==INF?-1:map[t]);
}
}
}
0