結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
atkrym
|
| 提出日時 | 2016-11-07 01:05:44 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 937 bytes |
| コンパイル時間 | 1,967 ms |
| コンパイル使用メモリ | 77,336 KB |
| 実行使用メモリ | 56,640 KB |
| 最終ジャッジ日時 | 2024-11-25 03:31:59 |
| 合計ジャッジ時間 | 6,986 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 19 |
ソースコード
import java.util.*;
public class Main {
private static Scanner sc = new Scanner(System.in);
private static int[] dp;
private static int n;
public static void main(String[] args) throws Exception {
n = sc.nextInt();
dp = new int[n+1];
dfs(1,1);
int ret = dp[n];
if (ret==0) {
System.out.println(-1);
} else {
System.out.println(ret);
}
}
private static void dfs(int i, int cnt) {
if (dp[i]>0) return;
dp[i] = cnt;
int c = count(i);
if (i-c>0) {
dfs(i-c,cnt+1);
}
if (i+c<=n) {
dfs(i+c,cnt+1);
}
}
private static int count(int val) {
String s = Integer.toBinaryString(val);
int cnt = 0;
for (int i = 0;i < s.length();i++) {
if (s.charAt(i)=='1') cnt++;
}
return cnt;
}
}
atkrym