結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  totori_nyaa | 
| 提出日時 | 2020-02-11 19:45:55 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 857 bytes | 
| コンパイル時間 | 1,643 ms | 
| コンパイル使用メモリ | 173,704 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-01 09:38:56 | 
| 合計ジャッジ時間 | 2,551 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef array<int,2> ar;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    
    int n;
    cin>>n;
    n++;
    bool used[n]={};
    int d[n]={};
    for(int i=0;i<n;i++) d[i]=1e9;
    d[1]=1;
    priority_queue<ar,vector<ar>,greater<ar>> pq;
    pq.push({1,1});
    while(pq.size()){
        ar p = pq.top(); pq.pop();
        if(used[p[1]]) continue;
        used[p[1]]=1;
        int cnt = 0;
        d[p[1]]=min(d[p[1]],p[0]);
        for(int i=0;i<20;i++){
            if(p[1] & (1<<i)) cnt++;
        }
        if(p[1]+cnt<n && !used[p[1]+cnt]) pq.push({p[0]+1,p[1]+cnt});
        if(p[1]-cnt>1 && !used[p[1]-cnt]) pq.push({p[0]+1,p[1]-cnt});
    }
    if(d[n-1]==1e9)cout<<-1<<endl;
    else cout << d[n-1] << endl;
    
}
            
            
            
        