結果

問題 No.3 ビットすごろく
ユーザー mannshi222jpmannshi222jp
提出日時 2022-02-07 22:04:34
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,542 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 29,564 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-04 12:07:57
合計ジャッジ時間 2,970 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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];
        int bits;

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

        for( int i; i < 10000; 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( idou[i] == 0 ) {
                idou[i] = step;

                setstep( idou, i-bit(i), idou[i]+1, N );
                if( i+ bit(i) <= 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 );
        //if( i+ bit(i) <= 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