結果

問題 No.3 ビットすごろく
ユーザー fal_rndfal_rnd
提出日時 2016-11-10 00:16:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 654 bytes
コンパイル時間 2,122 ms
コンパイル使用メモリ 74,164 KB
実行使用メモリ 56,272 KB
最終ジャッジ日時 2023-09-14 00:12:18
合計ジャッジ時間 7,560 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,900 KB
testcase_01 AC 120 ms
55,800 KB
testcase_02 AC 121 ms
55,620 KB
testcase_03 AC 121 ms
56,076 KB
testcase_04 AC 119 ms
55,496 KB
testcase_05 AC 122 ms
55,992 KB
testcase_06 AC 121 ms
56,184 KB
testcase_07 AC 121 ms
55,840 KB
testcase_08 AC 122 ms
56,076 KB
testcase_09 AC 124 ms
55,996 KB
testcase_10 AC 129 ms
55,596 KB
testcase_11 AC 121 ms
55,804 KB
testcase_12 AC 121 ms
55,768 KB
testcase_13 AC 123 ms
55,724 KB
testcase_14 AC 127 ms
55,944 KB
testcase_15 AC 132 ms
55,496 KB
testcase_16 AC 128 ms
56,272 KB
testcase_17 AC 129 ms
55,728 KB
testcase_18 AC 120 ms
55,460 KB
testcase_19 AC 128 ms
55,856 KB
testcase_20 AC 121 ms
55,852 KB
testcase_21 AC 120 ms
53,820 KB
testcase_22 AC 134 ms
55,708 KB
testcase_23 AC 129 ms
56,140 KB
testcase_24 AC 129 ms
55,968 KB
testcase_25 AC 130 ms
55,900 KB
testcase_26 AC 123 ms
55,400 KB
testcase_27 AC 124 ms
55,796 KB
testcase_28 AC 131 ms
55,904 KB
testcase_29 AC 125 ms
55,804 KB
testcase_30 AC 120 ms
55,784 KB
testcase_31 AC 121 ms
55,480 KB
testcase_32 AC 125 ms
55,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
class B{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {
		int in = Integer.parseInt(s.next());
		int[] m = new int[in];
		Queue<Integer> q = new ArrayDeque<Integer>();

		Arrays.fill(m, Integer.MAX_VALUE);
		m[0]=1;

		q.add(Integer.valueOf(0));
		while(!q.isEmpty()) {
			int i = q.poll(), d = Integer.bitCount(i+1),
				a = i-d, b = i+d;

			if(a>=0        && m[a]>m[i]+1) {
				m[a]=m[i]+1;
				q.add(a);
			}
			if(b< in && m[b]>m[i]+1) {
				m[b]=m[i]+1;
				q.add(b);
			}
		}
		if(m[in-1]==Integer.MAX_VALUE) {
			System.out.println(-1);
		}else {
			System.out.println(m[in-1]);
		}
	}
}
0