結果

問題 No.3 ビットすごろく
ユーザー DAZYDAZY
提出日時 2017-05-21 20:41:00
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 2,000 bytes
コンパイル時間 4,613 ms
コンパイル使用メモリ 77,068 KB
実行使用メモリ 193,536 KB
最終ジャッジ日時 2023-10-19 12:05:43
合計ジャッジ時間 12,742 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 RE -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
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;
        went[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;
                    }
                    //次に行けるマスを追加
                    if (j + mov < N + 1 && !went[j + mov]) {
                        next[i + 1][j + mov] = true;
                        went[j + mov] = true;
                    }
                    if (j - mov > 0 && !went[j - mov]) {
                        next[i + 1][j - mov] = true;
                        went[j - mov] = true;
                    }
                }
            }
            if (!flag) break;
        }
        for (int i = 0; i < 18; i++) {
            System.out.println(went[i]);
        }
        System.out.print(ans);
    }
}
0