結果

問題 No.3 ビットすごろく
ユーザー kou6839kou6839
提出日時 2014-11-08 13:44:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 736 bytes
コンパイル時間 4,561 ms
コンパイル使用メモリ 72,336 KB
実行使用メモリ 58,100 KB
最終ジャッジ日時 2023-09-13 22:54:03
合計ジャッジ時間 9,546 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,052 KB
testcase_01 AC 127 ms
55,708 KB
testcase_02 AC 128 ms
55,900 KB
testcase_03 AC 130 ms
55,616 KB
testcase_04 AC 129 ms
55,820 KB
testcase_05 AC 130 ms
56,036 KB
testcase_06 AC 131 ms
56,232 KB
testcase_07 AC 131 ms
55,984 KB
testcase_08 AC 131 ms
56,020 KB
testcase_09 AC 132 ms
55,876 KB
testcase_10 AC 136 ms
54,224 KB
testcase_11 AC 131 ms
55,884 KB
testcase_12 AC 132 ms
55,696 KB
testcase_13 AC 132 ms
55,704 KB
testcase_14 AC 138 ms
56,096 KB
testcase_15 AC 139 ms
55,760 KB
testcase_16 AC 138 ms
55,936 KB
testcase_17 AC 138 ms
55,788 KB
testcase_18 AC 127 ms
55,708 KB
testcase_19 AC 136 ms
56,224 KB
testcase_20 AC 129 ms
55,580 KB
testcase_21 AC 127 ms
55,884 KB
testcase_22 AC 134 ms
55,860 KB
testcase_23 AC 135 ms
58,100 KB
testcase_24 AC 137 ms
55,636 KB
testcase_25 AC 137 ms
56,060 KB
testcase_26 AC 127 ms
55,852 KB
testcase_27 AC 129 ms
55,840 KB
testcase_28 AC 136 ms
55,848 KB
testcase_29 AC 130 ms
55,992 KB
testcase_30 AC 128 ms
55,976 KB
testcase_31 AC 127 ms
56,076 KB
testcase_32 AC 130 ms
55,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int ans=1;
		int[] check=new int[N+1];
		Queue<Integer> queue = new LinkedList<>();
		queue.offer(1);
		check[1]=1;
		while(!queue.isEmpty()){
			int temp1 = queue.poll();
			int temp2 = temp1+Integer.bitCount(temp1);
			int temp3=temp1-Integer.bitCount(temp1);
			if(temp2<=N&&check[temp2]==0){
				queue.offer(temp2);
				check[temp2]=check[temp1]+1;
			}
			if(temp3>=1&&check[temp3]==0){
				queue.offer(temp3);
				check[temp3]=check[temp1]+1;
			}
		}
		if(check[N]==0){
			System.out.println(-1);
		}else{
			System.out.println(check[N]);
		}
	}
}	
0