結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-10-29 11:22:02 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 700 bytes | 
| コンパイル時間 | 721 ms | 
| コンパイル使用メモリ | 86,292 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-01 08:08:17 | 
| 合計ジャッジ時間 | 1,656 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
//#include<bits/stdc++.h>
using namespace std;
int main() {
	
	int n;
	cin>>n;
	queue<int>p;
	vector<int>x(n+2);
	for(int i=0;i<n+1;i++)
		x[i]=-1;
	p.push(1);
	x[1]=1;
	while(p.size()){
		int v=p.front();
		int c=0,d=v;
		while(d){
			if(d%2)c++;
			d/=2;
		}
		if(v-c>0&&x[v-c]==-1){
			p.push(v-c);
			x[v-c]=x[v]+1;
		}
		if(v+c<=n&&x[v+c]==-1){
			p.push(v+c);
			x[v+c]=x[v]+1;
		}
		p.pop();
	}
	
	cout<<x[n]<<endl;
	
	
	return 0;
}
	
            
            
            
        