結果
問題 | No.3 ビットすごろく |
ユーザー | shiyo1023 |
提出日時 | 2019-09-02 15:29:17 |
言語 | Java21 (openjdk 21) |
結果 |
MLE
|
実行時間 | - |
コード長 | 776 bytes |
コンパイル時間 | 3,108 ms |
コンパイル使用メモリ | 71,136 KB |
実行使用メモリ | 835,624 KB |
最終ジャッジ日時 | 2023-08-22 04:41:53 |
合計ジャッジ時間 | 5,761 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 110 ms
55,508 KB |
testcase_01 | AC | 106 ms
55,544 KB |
testcase_02 | MLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
import java.util.Scanner; public class Main { private static int N; private static int min = -1; private static boolean flag[] = new boolean[10000]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); dfs(1, 1); System.out.println(min); } private static void dfs(int a, int c){ if(a<1 || a>N){ return; } if(flag[a-1] == true){ return; } if(min != -1 && c>=min){ //flag[a-1] = true; return; } if(a==N){ min = c; } int b = Integer.bitCount(a); dfs(a+b, c+1); dfs(a-b, c+1); } }