結果

問題 No.3 ビットすごろく
ユーザー DAZYDAZY
提出日時 2017-05-19 13:57:27
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,739 bytes
コンパイル時間 3,622 ms
コンパイル使用メモリ 77,172 KB
実行使用メモリ 195,984 KB
最終ジャッジ日時 2023-10-19 02:45:23
合計ジャッジ時間 11,875 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,456 KB
testcase_01 AC 132 ms
57,300 KB
testcase_02 AC 131 ms
57,352 KB
testcase_03 AC 163 ms
62,212 KB
testcase_04 AC 156 ms
57,576 KB
testcase_05 AC 206 ms
88,928 KB
testcase_06 AC 172 ms
66,444 KB
testcase_07 AC 162 ms
59,600 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 215 ms
88,900 KB
testcase_13 AC 167 ms
62,400 KB
testcase_14 AC 250 ms
135,164 KB
testcase_15 AC 277 ms
151,924 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 163 ms
59,700 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 132 ms
57,340 KB
testcase_22 AC 253 ms
134,180 KB
testcase_23 AC 291 ms
195,576 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 132 ms
57,372 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 131 ms
57,328 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No3 {
    public static void main (String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        //tmp:今いるマスの目のコピー
        //mov:動けるマス数 loc:今いるマス目
        //flag:一度も動けない事があるかを監視
        int tmp;
        int ans = -1;
        int mov;
        boolean flag;

        //すでに行ったことのあるマスを記憶
        boolean[] went = new boolean[N+1];
        //次に行くマスを記憶
        boolean[][] next = new boolean[N+1][N+1];

        for (int i = 0; i < N+1; i++) {
            went[i] = false;
            for (int j = 0; j < N+1; j++) {
                next[i][j] = false;
            }
        }
        next[1][1] = true;
        for (int i = 1; i < N+1; i++) {
            flag = false;
            for (int j = 1; j < N+1; j++) {
                if (next[i][j]) {
                    flag = true;
                    if (j == N) {
                        ans = i;
                        break;
                    }
                    mov = 0;
                    tmp = j;
                    //2進数のときbitが1の数を数える
                    while (tmp != 0) {
                        mov += tmp & 1;
                        tmp = tmp >> 1;
                    }
                    went[j] = true;
                    //次に行けるマスを追加
                    if (j + mov < N + 1 && !went[j + mov]) next[i + 1][j + mov] = true;
                    else if (j - mov > 0 && !went[j - mov]) next[i + 1][j - mov] = true;
                }
            }
            if (!flag) break;
        }
        System.out.print(ans);
    }
}
0