結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
jp_ste
|
| 提出日時 | 2016-03-04 13:29:16 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 956 bytes |
| コンパイル時間 | 2,331 ms |
| コンパイル使用メモリ | 74,852 KB |
| 実行使用メモリ | 56,108 KB |
| 最終ジャッジ日時 | 2024-09-24 14:03:22 |
| 合計ジャッジ時間 | 7,151 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 WA * 10 |
ソースコード
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int N;
static int minCount[];
public static void main(String[] args) {
try (Scanner scan = new Scanner(System.in)) {
N = scan.nextInt();
minCount = new int[N+1];
Arrays.fill(minCount, Integer.MAX_VALUE);
minCount[1] = 1;
solve(1, 1);
System.out.println(minCount[N]);
}
}
static void solve(int p, int c) {
int front = p + Integer.bitCount(p);
if(front <= N) {
if(c+1 < minCount[front]) {
minCount[front] = c+1;
solve(front, c+1);
}
}
int back = p - Integer.bitCount(p);
if(back >= 1) {
if(c+1 < minCount[back]) {
minCount[back] = c+1;
solve(back, c+1);
}
}
}
}
jp_ste