結果

問題 No.3 ビットすごろく
ユーザー fanta fan
提出日時 2022-02-12 23:15:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 699 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 170,652 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-29 02:29:15
合計ジャッジ時間 3,420 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int walk(int n, int count, vector<int> a){
    if( n == 1){
        return count;
    }
    if( count > 14){
        return 20;
    }
    int res = 20;
    for( int i = max(n - 15,0) ; i < min( n + 15, (int)a.size() ); i++){
        if( abs( i - n ) == a.at(i) ){
            res = min( res, walk(i, count + 1, a));
        }
    }
    return res;
}

int main(){
    int n;
    vector<int> a;
    cin >> n;
    for(int i =0; i< n + 1; i++){
        a.push_back( (int)bitset<32>(i).count() );
    }
    int res;
    res = walk(n,0, a);
    if(res == 20){
        cout << -1 << endl;
    }else{
        cout << res + 1 << endl;
    }

    return 0;


}
0