結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-11-12 09:30:20 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,128 bytes |
| コンパイル時間 | 4,088 ms |
| コンパイル使用メモリ | 78,828 KB |
| 実行使用メモリ | 56,276 KB |
| 最終ジャッジ日時 | 2024-12-31 10:00:08 |
| 合計ジャッジ時間 | 9,514 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 15 |
ソースコード
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;
}
}
}