結果

問題 No.3 ビットすごろく
コンテスト
ユーザー Doneru
提出日時 2019-02-22 18:11:29
言語 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
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 597 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,084 ms
コンパイル使用メモリ 186,584 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-22 06:27:00
合計ジャッジ時間 2,323 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int ret = -1;
int n;
map<int,int> check;

void calc(int cur,int cnt){
    if(cur == n){
        ret = cnt;
    }
    check[cur] = cnt;
    int num = 0;
    int tmp = cur;
    while(tmp > 0){
        if(tmp % 2 == 1)num++;
        tmp /= 2;
    }
    if(cur + num <= n){
        if(check[cur+num] == 0 || check[cur+num] > cnt+1)
        calc(cur+num,cnt+1);
    }
    if(cur - num >= 1){
        if(check[cur-num] == 0 || check[cur-num] > cnt+1)
        calc(cur-num,cnt+1);
    }
}

int main(){
    cin >> n;
    calc(1,1);
    cout << ret << endl;
}
0