結果

問題 No.3 ビットすごろく
ユーザー mazeppa1108
提出日時 2015-05-31 18:30:10
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,067 bytes
コンパイル時間 2,934 ms
コンパイル使用メモリ 77,360 KB
実行使用メモリ 55,816 KB
最終ジャッジ日時 2024-07-06 13:04:04
合計ジャッジ時間 7,738 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 13 RE * 1
権限があれば一括ダウンロードができます

ソースコード

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