結果

問題 No.3 ビットすごろく
ユーザー spaciaspacia
提出日時 2015-12-16 11:06:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 163 ms / 5,000 ms
コード長 691 bytes
コンパイル時間 3,105 ms
コンパイル使用メモリ 72,048 KB
実行使用メモリ 51,736 KB
最終ジャッジ日時 2023-09-13 23:33:51
合計ジャッジ時間 6,724 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,316 KB
testcase_01 AC 42 ms
49,360 KB
testcase_02 AC 42 ms
49,296 KB
testcase_03 AC 65 ms
50,696 KB
testcase_04 AC 54 ms
50,688 KB
testcase_05 AC 82 ms
50,784 KB
testcase_06 AC 62 ms
50,644 KB
testcase_07 AC 57 ms
50,896 KB
testcase_08 AC 72 ms
50,900 KB
testcase_09 AC 103 ms
51,500 KB
testcase_10 AC 127 ms
50,964 KB
testcase_11 AC 94 ms
51,116 KB
testcase_12 AC 80 ms
49,368 KB
testcase_13 AC 59 ms
51,152 KB
testcase_14 AC 120 ms
51,200 KB
testcase_15 AC 157 ms
51,400 KB
testcase_16 AC 144 ms
51,736 KB
testcase_17 AC 155 ms
51,356 KB
testcase_18 AC 57 ms
51,280 KB
testcase_19 AC 161 ms
51,712 KB
testcase_20 AC 52 ms
50,736 KB
testcase_21 AC 42 ms
49,416 KB
testcase_22 AC 122 ms
51,016 KB
testcase_23 AC 163 ms
51,096 KB
testcase_24 AC 161 ms
51,304 KB
testcase_25 AC 158 ms
51,444 KB
testcase_26 AC 41 ms
49,460 KB
testcase_27 AC 60 ms
50,772 KB
testcase_28 AC 139 ms
51,256 KB
testcase_29 AC 96 ms
51,080 KB
testcase_30 AC 43 ms
49,368 KB
testcase_31 AC 43 ms
49,256 KB
testcase_32 AC 89 ms
50,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.math.*;

class Main3 {
	
	static int max;
	static int[] minPass;
	
	public static void getPass (int i, int pass) {
		if (i <= 0 || max <= i) return;
		if (minPass[i] != -1 && minPass[i] <= pass) return;
		
		minPass[i] = pass;
		int b = Integer.bitCount(i);
		getPass(i - b, pass + 1);
		getPass(i + b, pass + 1);
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		max = n + 1;
		minPass = new int[max];
		Arrays.fill(minPass , -1);
		
		getPass(1, 1);
		
		System.out.println(minPass[n]);
		
	}
}
0