結果

問題 No.3 ビットすごろく
ユーザー mazeppa1108mazeppa1108
提出日時 2015-05-31 18:30:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,067 bytes
コンパイル時間 3,181 ms
コンパイル使用メモリ 74,288 KB
実行使用メモリ 57,948 KB
最終ジャッジ日時 2023-09-20 18:08:19
合計ジャッジ時間 8,897 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,700 KB
testcase_01 AC 123 ms
56,332 KB
testcase_02 AC 124 ms
55,908 KB
testcase_03 AC 134 ms
55,872 KB
testcase_04 AC 125 ms
56,448 KB
testcase_05 AC 137 ms
55,912 KB
testcase_06 AC 134 ms
56,020 KB
testcase_07 AC 124 ms
55,872 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 136 ms
56,500 KB
testcase_13 AC 131 ms
56,084 KB
testcase_14 AC 138 ms
55,724 KB
testcase_15 AC 141 ms
55,724 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 122 ms
55,980 KB
testcase_19 WA -
testcase_20 AC 125 ms
57,948 KB
testcase_21 AC 123 ms
55,888 KB
testcase_22 AC 137 ms
55,804 KB
testcase_23 AC 139 ms
55,500 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 123 ms
56,120 KB
testcase_31 AC 122 ms
55,704 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

import javax.naming.directory.SearchResult;

public class Main2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[] visited = new boolean[n];
		visited[0] = true;
		int searchList[] = new int[n];
		int countTable[] = new int[n];
		countTable[1] = 1;
		searchList[1] = 1;
		int j = 2;
		int k = 1;
		while (searchList[k] != 0) {
			//System.out.println("new Root");
			int move = 0;
			int i = searchList[k];
			int count = countTable[k];
			while (i <= n) {
				visited[i] = true;
				move = Integer.bitCount(i);
				if (visited[i - move]) {
					i += move;
					count++;
					//System.out.println(i);
					if (i == n) {
						System.out.println(count);
						return;
					}
				} else {
					if (i - move >= 0) {
						searchList[j] = (i - move);
						//System.out.println("add SearchList");
						//System.out.println(i-move);
						visited[i - move] = true;
						countTable[j] = count + 1;
						j++;
					}
				}
			}
			k++;
		}
		System.out.println("-1");
		return;
	}
}
0