結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-31 14:22:19 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,271 bytes |
| コンパイル時間 | 3,520 ms |
| コンパイル使用メモリ | 77,176 KB |
| 実行使用メモリ | 55,440 KB |
| 最終ジャッジ日時 | 2024-11-15 16:47:16 |
| 合計ジャッジ時間 | 8,890 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 17 |
ソースコード
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
if (N == 1) {
System.out.println(0);
return;
}
int[] map = new int[N+1];
for (int i = 1; i <= N; i++) {
map[i] = Integer.bitCount(i);
}
boolean[] comp = new boolean[N+1];
for (int i = 1; i < N; i++) {
int p = i;
while(p < N) {
if (p+map[p] == N) {
comp[i] = true;
}
p += map[p];
}
}
int p = 1;
int count = 1;
int min = Integer.MAX_VALUE;
while(p < N) {
if (!comp[p] && p-map[p] > 0 && comp[p-map[p]]) {
int tmpCount = count+1;
int tmpP = p-map[p];
while(tmpP != N) {
tmpCount++;
tmpP += map[tmpP];
}
min = Math.min(min, tmpCount);
}
count++;
if (p+map[p] == N) {
min = Math.min(min, count);
}
p += map[p];
}
System.out.println(min == Integer.MAX_VALUE ? -1 : min);
}
}