結果

問題 No.3 ビットすごろく
コンテスト
ユーザー drymouse
提出日時 2019-12-27 20:58:14
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 898 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 211 ms
コンパイル使用メモリ 41,728 KB
最終ジャッジ日時 2026-02-22 05:04:56
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int bit(int a);

int main(void) {
    int N;
    int s = 1;
    int c = 1;
    int b;
    int ng = 0;
    int n0g[10] = {0};
    scanf("%d", &N);
    n0g[0] = 1;
    if (N == 1) {
        printf("%d\n", s);
        return EXIT_SUCCESS;
    }
    for (;;) {
        b = bit(c);
        s++;
        if (!(s % 10)) {
            ng = c;
        }
        if (c+b == N) {
            printf("%d\n", s);
            break;
        } else if (c+b > N) {
            c -= b;
        } else {
            c += b;
        }
        if (c == ng) {
            printf("%d\n", -1);
            return EXIT_SUCCESS;
        }
    }
    return EXIT_SUCCESS;
}

int bit(int a) {
    int t = 0;
    int p;
    for (int i = 15; i >= 0; i--) {
        p = pow(2, i);
        if (a >= p) {
            t++;
            a -= p;
        }
    }
    return t;
}
0