結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  iomir | 
| 提出日時 | 2023-04-23 22:22:14 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 583 bytes | 
| コンパイル時間 | 2,064 ms | 
| コンパイル使用メモリ | 171,532 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-08 03:54:24 | 
| 合計ジャッジ時間 | 2,971 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
using ll = long long;
const ll INF=1ll<<60;
int main(){
    ll N;
    cin>>N;
    vector<ll> d(N+1,INF);
    d[1]=0;
    queue<ll> q;
    q.push({1});
    while(!q.empty()){
        auto x=q.front();q.pop();
        auto a=__builtin_popcount(x);
        if(x-a>=1&&d[x-a]==INF){
            d[x-a]=d[x]+1;
            q.push(x-a);
        }
        if(x+a<=N&&d[x+a]==INF){
            d[x+a]=d[x]+1;
            q.push(x+a);
        }
    }
    if(d[N]==INF)d[N]=-2;
    cout << d[N]+1 << endl;
    
}
            
            
            
        