結果

問題 No.3 ビットすごろく
ユーザー drymousedrymouse
提出日時 2020-01-02 21:40:44
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 995 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 28,924 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-14 18:41:04
合計ジャッジ時間 2,623 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 7 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 7 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 0 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int bit(int a);

int main(void) {
    int N;
    int s = 1; // step
    int c = 0; // check

    scanf("%d", &N);

    int math[10001] = {0};
    math[1] = 1;
    for (; ; s++) {
        c = 0;
        for (int i = 1; i <= N; i++) {
            if (math[i] == s) {
                int d = bit(i); // distance
                if (i+d == N) {
                    printf("%d\n", s+1);
                    exit(EXIT_SUCCESS);
                }
                if (i+d < N && !math[i+d]) {
                    math[i+d] = s+1;
                    c = 1;
                }
                if (0 < i-d && !math[i-d]) {
                    math[i-d] = s+1;
                    c = 1;
                }
            }  
        }
        if (!c) {
            printf("-1\n");
            exit(EXIT_SUCCESS);
        }
    }
    return EXIT_SUCCESS;
}

int bit(int a) {
    int t = 0;
    for (; a;) {
        if (a % 2) {t++;};
        a /= 2;
    }
    return t;
}
0