結果

問題 No.3 ビットすごろく
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-20 12:44:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 771 ms / 5,000 ms
コード長 1,432 bytes
コンパイル時間 3,603 ms
コンパイル使用メモリ 74,588 KB
実行使用メモリ 253,216 KB
最終ジャッジ日時 2023-09-13 23:09:40
合計ジャッジ時間 15,265 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
56,124 KB
testcase_01 AC 118 ms
55,824 KB
testcase_02 AC 123 ms
55,856 KB
testcase_03 AC 200 ms
67,924 KB
testcase_04 AC 154 ms
56,312 KB
testcase_05 AC 258 ms
112,408 KB
testcase_06 AC 198 ms
68,352 KB
testcase_07 AC 158 ms
60,308 KB
testcase_08 AC 206 ms
87,812 KB
testcase_09 AC 338 ms
135,464 KB
testcase_10 AC 571 ms
188,228 KB
testcase_11 AC 291 ms
131,896 KB
testcase_12 AC 245 ms
115,240 KB
testcase_13 AC 159 ms
64,996 KB
testcase_14 AC 517 ms
191,516 KB
testcase_15 AC 702 ms
246,044 KB
testcase_16 AC 533 ms
231,272 KB
testcase_17 AC 728 ms
240,692 KB
testcase_18 AC 156 ms
60,608 KB
testcase_19 AC 755 ms
253,216 KB
testcase_20 AC 129 ms
55,856 KB
testcase_21 AC 110 ms
55,956 KB
testcase_22 AC 523 ms
189,172 KB
testcase_23 AC 755 ms
248,740 KB
testcase_24 AC 771 ms
251,432 KB
testcase_25 AC 757 ms
246,100 KB
testcase_26 AC 123 ms
56,112 KB
testcase_27 AC 165 ms
65,072 KB
testcase_28 AC 512 ms
232,780 KB
testcase_29 AC 316 ms
135,376 KB
testcase_30 AC 119 ms
56,064 KB
testcase_31 AC 116 ms
55,708 KB
testcase_32 AC 294 ms
131,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int n = koko.nextInt();
        boolean[][] goal = new boolean[2*n+1][n+1];
        goal[1][1]=true;
        boolean[] judge = new boolean[n+1];
        judge[1] = true;
        for(int i=1; i<2*n+1; i++){
            for(int j=1; j<n+1; j++){
                if(goal[i][j]){
                    String jud = Integer.toBinaryString(j);
                    char[] num = jud.toCharArray();
                    int count=0;
                    for(int k=0; k<num.length; k++){
                        if(num[k]=='1'){
                            count++;
                        }
                    }
                    if(j+count<n+1&&!judge[j+count]){
                        goal[i+1][j+count]=true;
                        judge[j+count]=true;
                    }
                    if(j-count>1&&!judge[j-count]){
                        goal[i+1][j-count]=true;
                        judge[j-count]=true;
                    }
                }
            }
        }
        boolean flag = false;
        for(int i=1; i<2*n+1; i++){
            if(goal[i][n]){
                System.out.println(i);
                flag=true;
                break;
            }
        }
        if(!flag){
            System.out.println(-1);
        }
        
    }
    
}
0