結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
kohaku_kohaku
|
| 提出日時 | 2016-12-12 00:00:33 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 5,000 ms |
| コード長 | 704 bytes |
| 記録 | |
| コンパイル時間 | 1,712 ms |
| コンパイル使用メモリ | 83,112 KB |
| 実行使用メモリ | 42,600 KB |
| 最終ジャッジ日時 | 2026-03-22 04:45:36 |
| 合計ジャッジ時間 | 4,930 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int [] c = new int [N+1];
c[1]=1;
Queue<Integer> q = new LinkedList<>();
q.add(1);
while(!q.isEmpty()){
int t = q.poll();
int p = Integer.bitCount(t);
int b = t-p;
int f = t+p;
if(b>0&&c[b]==0){
c[b]=c[t]+1;
q.add(b);
}
if(f<=N&&c[f]==0){
c[f]=c[t]+1;
q.add(f);
}
}
if(c[N]==0)c[N]=-1;
System.out.println(c[N]);
}
}
kohaku_kohaku