結果

問題 No.3 ビットすごろく
ユーザー Doneru
提出日時 2019-02-22 17:54:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 550 bytes
コンパイル時間 1,350 ms
コンパイル使用メモリ 168,360 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-24 18:47:31
合計ジャッジ時間 2,431 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#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){
        if(ret == -1)ret = cnt;
        else ret = min(ret,cnt);
    }
    check[cur]++;
    int num = 0;
    while(cur > 0){
        if(cur % 2 == 1)num++;
        cur /= 2;
    }
    if(cur + num <= n && check[cur+num] == 0){
        calc(cur+num,cnt+1);
    }
    if(cur - num >= 1 && check[cur-num] == 0){
        calc(cur-num,cnt+1);
    }
}

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