結果

問題 No.3 ビットすごろく
ユーザー mannshi222jpmannshi222jp
提出日時 2022-02-07 22:59:13
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,188 ms / 5,000 ms
コード長 1,491 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 30,012 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 15:06:10
合計ジャッジ時間 17,427 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 67 ms
4,376 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 327 ms
4,376 KB
testcase_06 AC 83 ms
4,376 KB
testcase_07 AC 29 ms
4,376 KB
testcase_08 AC 206 ms
4,376 KB
testcase_09 AC 552 ms
4,380 KB
testcase_10 AC 796 ms
4,380 KB
testcase_11 AC 461 ms
4,380 KB
testcase_12 AC 309 ms
4,384 KB
testcase_13 AC 48 ms
4,380 KB
testcase_14 AC 743 ms
4,380 KB
testcase_15 AC 1,157 ms
4,380 KB
testcase_16 AC 999 ms
4,376 KB
testcase_17 AC 1,124 ms
4,376 KB
testcase_18 AC 36 ms
4,380 KB
testcase_19 AC 1,188 ms
4,376 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 764 ms
4,376 KB
testcase_23 AC 1,186 ms
4,376 KB
testcase_24 AC 1,186 ms
4,376 KB
testcase_25 AC 1,156 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 57 ms
4,376 KB
testcase_28 AC 954 ms
4,380 KB
testcase_29 AC 476 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 404 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int bit( int i );
int setstep( int *idou, int i, int step, int N );

int main()
{
        int N;
        int idou[10000+1];
        int bits;

        scanf("%d\n", &N );

        for( int i; i < 10000+1; i++ ) {
                idou[i] = 0;
        }

        idou[1] = 1;
        setstep( idou, 1-bit(1), idou[1]+1, N );
        setstep( idou, 1+bit(1), idou[1]+1, N );
/**/

/*
        for( int i = 0; i <= N; i++ ) {
                printf("%d %d\n", i,  idou[i]  );
        }
/**/
        if( idou[N] == 0 ) {
                printf("-1\n");
        }
        else {
                printf("%d\n", idou[N]);
        }

        return 0;
}

int setstep( int *idou, int i, int step, int N )
{
        if( step > N ) {
                return 0;
        }
        if( i <= 0 ) {
                return 0;
        }
        if( i > N ) {
                return 0;
        }

        if( idou[i] == 0 ) {
                idou[i] = step;

                setstep( idou, i-bit(i), idou[i]+1, N );
                setstep( idou, i+bit(i), idou[i]+1, N );
                return 0;
        }

        if( idou[i] > step ) {
                idou[i] = step;
                setstep( idou, i-bit(i), idou[i]+1, N );
                setstep( idou, i+bit(i), idou[i]+1, N );
        }

        return 0;
}

int bit( int i ){
        int num = 0;
        int mask = 1;
    for ( ; mask != 0 ; mask = mask << 1 ){
        if (i & mask )
            num++;
    }
        return num;
}
0