結果

問題 No.3 ビットすごろく
ユーザー scachescache
提出日時 2014-11-12 09:30:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,128 bytes
コンパイル時間 5,045 ms
コンパイル使用メモリ 74,464 KB
実行使用メモリ 57,672 KB
最終ジャッジ日時 2023-08-30 03:17:22
合計ジャッジ時間 11,007 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,984 KB
testcase_01 AC 124 ms
55,472 KB
testcase_02 AC 125 ms
55,764 KB
testcase_03 AC 128 ms
55,524 KB
testcase_04 AC 127 ms
56,164 KB
testcase_05 AC 127 ms
56,164 KB
testcase_06 AC 125 ms
55,868 KB
testcase_07 AC 126 ms
56,132 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 127 ms
55,612 KB
testcase_13 AC 126 ms
55,804 KB
testcase_14 AC 128 ms
55,700 KB
testcase_15 AC 127 ms
55,564 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 125 ms
56,084 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 125 ms
55,528 KB
testcase_22 AC 128 ms
55,604 KB
testcase_23 AC 126 ms
55,880 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 124 ms
55,900 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 123 ms
55,844 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class BitSugoroku {


	public static void main(String[] args) {
		BitSugoroku p = new BitSugoroku();
	}

	public BitSugoroku() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		solve(n);
	}

	public void solve(int n) {
		
		int[] isVisit = new int[n+1];
		Arrays.fill(isVisit, -1);
		isVisit[0] = isVisit[1] = 1;
	
		PriorityQueue<P> queue = new PriorityQueue<P>();
		queue.offer(new P(1, 1));
		while(!queue.isEmpty()){
			P p = queue.poll();
			
			isVisit[p.x] = p.d;
			int move = Integer.bitCount(p.x);
			if(p.x+move <= n && isVisit[p.x+move] < 0){
				queue.offer(new P(p.x+move, p.d+1));
			}else if(p.x-move >= 1 && isVisit[p.x-move] < 0){
				queue.offer(new P(p.x-move, p.d+1));
			}
		}
		
		System.out.println(isVisit[n]);
		
	}

	public class P implements Comparable<P>{
		public int x;
		public int d;
		
		public P(int x, int d) {
			this.x = x;
			this.d = d;
		}

		@Override
		public int compareTo(P o) {
			return this.d - o.d;
		}

	}
	
}
0