結果

問題 No.3 ビットすごろく
ユーザー リチウムリチウム
提出日時 2014-11-21 21:12:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 173 ms / 5,000 ms
コード長 918 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 75,176 KB
実行使用メモリ 57,940 KB
最終ジャッジ日時 2023-09-13 22:56:06
合計ジャッジ時間 8,092 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,712 KB
testcase_01 AC 126 ms
55,724 KB
testcase_02 AC 123 ms
55,984 KB
testcase_03 AC 126 ms
55,876 KB
testcase_04 AC 126 ms
55,992 KB
testcase_05 AC 128 ms
55,868 KB
testcase_06 AC 128 ms
56,068 KB
testcase_07 AC 128 ms
56,032 KB
testcase_08 AC 129 ms
55,916 KB
testcase_09 AC 145 ms
55,984 KB
testcase_10 AC 154 ms
56,072 KB
testcase_11 AC 145 ms
56,072 KB
testcase_12 AC 129 ms
55,692 KB
testcase_13 AC 126 ms
56,016 KB
testcase_14 AC 157 ms
57,940 KB
testcase_15 AC 160 ms
55,716 KB
testcase_16 AC 156 ms
56,192 KB
testcase_17 AC 158 ms
55,752 KB
testcase_18 AC 126 ms
55,980 KB
testcase_19 AC 173 ms
55,888 KB
testcase_20 AC 135 ms
55,780 KB
testcase_21 AC 125 ms
56,060 KB
testcase_22 AC 157 ms
56,008 KB
testcase_23 AC 161 ms
55,572 KB
testcase_24 AC 162 ms
55,932 KB
testcase_25 AC 159 ms
55,864 KB
testcase_26 AC 124 ms
55,496 KB
testcase_27 AC 128 ms
55,536 KB
testcase_28 AC 161 ms
55,656 KB
testcase_29 AC 145 ms
55,492 KB
testcase_30 AC 123 ms
55,688 KB
testcase_31 AC 124 ms
55,864 KB
testcase_32 AC 144 ms
56,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	
	
  public static void main(String[] args) {
	  Scanner sc=new Scanner(System.in);
	  int n=sc.nextInt();
	  int dp[]=new int[n+1];
	  Arrays.fill(dp,-1);
	  dp[1]=1;
	  Queue <conect>next=new PriorityQueue<>();
	  next.add(new conect(1,1));
	  while(!next.isEmpty()){
		  conect c=next.poll();
		  int bit=Integer.bitCount(c.num);
		  int to=c.num-bit;
		  int j=0;
		  while(j<2){
		  if((to>0 && to<=n) && (dp[to]>dp[c.num]+1 || dp[to]==-1)){
			  dp[to]=dp[c.num]+1;
			  next.add(new conect(dp[to],to));
		  }
		  to=c.num+bit;
		  j++;
		  }
	  }
	  System.out.println(dp[n]);
  }
}

class conect implements Comparable<conect> {
	int dp;
	int num;

	public conect(int dp, int num) {
		this.dp = dp;
		this.num = num;
	}

	public conect() {
	}

	@Override
	public int compareTo(conect o) {
		return this.num - o.num;
	}

}
0