結果

問題 No.3 ビットすごろく
ユーザー DAZYDAZY
提出日時 2017-05-18 16:37:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 5,642 ms
コンパイル使用メモリ 74,476 KB
実行使用メモリ 57,908 KB
最終ジャッジ日時 2023-10-18 23:10:54
合計ジャッジ時間 10,336 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
57,236 KB
testcase_01 AC 121 ms
57,184 KB
testcase_02 AC 126 ms
57,588 KB
testcase_03 AC 124 ms
55,384 KB
testcase_04 AC 126 ms
57,524 KB
testcase_05 AC 127 ms
57,796 KB
testcase_06 AC 124 ms
57,632 KB
testcase_07 AC 125 ms
55,472 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 125 ms
57,272 KB
testcase_13 AC 125 ms
57,720 KB
testcase_14 AC 129 ms
57,512 KB
testcase_15 AC 130 ms
57,448 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 124 ms
57,592 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 123 ms
57,204 KB
testcase_22 AC 129 ms
57,908 KB
testcase_23 AC 117 ms
56,296 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 126 ms
57,484 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 134 ms
57,600 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();
        int tmp = 1;
        int ans = 1;
        int mov;
        int loc = 1;

        while (true) {
            if (loc == N) break;
            mov = 0;
            while (tmp != 0) {
                mov += tmp & 1;
                tmp = tmp >> 1;
            }
            //System.out.println(ans);
            if (ans > N) {
                ans = -1;
                break;
            } else if (loc + mov < N + 1) loc += mov;
            else if (loc - mov > 0) loc -= mov;
            tmp = loc;
            ans ++;
        }
        System.out.print(ans);
    }
}
0