結果

問題 No.3 ビットすごろく
ユーザー izryt(趣味)
提出日時 2016-01-17 15:03:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 486 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 158,432 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-19 20:19:44
合計ジャッジ時間 2,037 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#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