結果

問題 No.3 ビットすごろく
コンテスト
ユーザー izryt(趣味)
提出日時 2016-01-17 15:03:11
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 486 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 938 ms
コンパイル使用メモリ 178,212 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-04-08 08:45:55
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

bool used[10001];
int N;

int bitcount(int a)
{
    int cnt = 0;
    while (a) {
        cnt += a & 1;
        a >>= 1;
    }
    return cnt;
}

int rec(int depth, int i)
{
    if (i == N) return depth + 1;
    if (i < 1 || i > N || used[i]) return -1e9;

    used[i] = true;

    int a = bitcount(i);

    return max(rec(depth + 1, i + a), rec(depth + 1, i - a));
}

int main()
{
    cin >> N;

    cout << max(rec(0, 1), -1) << endl;
}
0