結果

問題 No.3 ビットすごろく
ユーザー mazeppa1108mazeppa1108
提出日時 2015-06-05 01:28:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 987 bytes
コンパイル時間 2,726 ms
コンパイル使用メモリ 73,904 KB
実行使用メモリ 56,292 KB
最終ジャッジ日時 2023-09-20 19:11:40
合計ジャッジ時間 9,098 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,656 KB
testcase_01 AC 121 ms
56,056 KB
testcase_02 AC 121 ms
55,704 KB
testcase_03 AC 131 ms
55,664 KB
testcase_04 AC 122 ms
55,384 KB
testcase_05 AC 135 ms
55,832 KB
testcase_06 AC 131 ms
55,876 KB
testcase_07 AC 130 ms
56,292 KB
testcase_08 AC 132 ms
53,516 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 131 ms
55,520 KB
testcase_13 AC 129 ms
55,792 KB
testcase_14 AC 136 ms
55,832 KB
testcase_15 AC 137 ms
55,828 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 126 ms
55,888 KB
testcase_19 WA -
testcase_20 AC 121 ms
55,916 KB
testcase_21 AC 119 ms
55,408 KB
testcase_22 AC 135 ms
56,144 KB
testcase_23 AC 137 ms
55,848 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 121 ms
56,036 KB
testcase_31 AC 121 ms
55,804 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	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[0] = 1;
		countTable[n-1] = n+1;
		searchList[0] = 1;
		int j = 1;
		int k = 0;
		while (searchList[k] != 0) {
			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++;
					if (i == n) {
						countTable[n-1] = Math.min (count, countTable[n-1]);
					}
				} else {
					if (i - move >= 0) {
						searchList[j] = (i - move);
						visited[i - move] = true;
						countTable[j] = count + 1;
						j++;
					}
				}
			}
			k++;
		}
		if (countTable[n-1] == (n+1)) {
			System.out.println("-1");
		} else {
			System.out.println(countTable[n-1]);
		}
	}
}
0