結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  777yuuki12323 | 
| 提出日時 | 2017-06-19 18:26:25 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,296 bytes | 
| コンパイル時間 | 847 ms | 
| コンパイル使用メモリ | 76,984 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-01 08:44:59 | 
| 合計ジャッジ時間 | 1,815 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:79:15: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   79 |         cout<<ans<<endl;
      |               ^~~
            
            ソースコード
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>
typedef long long ll;
#define fi first
#define se second
const ll mod = 1000000007;
//              123456789
using namespace std;
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
queue<int> Q;
int cost[11234];
int N;
int main(){
	
	fill(cost, cost+11234, mod);
	cost[1] = 1;
	
	Q.push( 1 );
	
	cin>>N;
	
	int ans;
	int num;
	int next;
	int flag = 0;
	int j[2] = { 1, -1 };
	int i;
	
	if( N > 1 ){
		while( !Q.empty() ){
			num = Q.front();
			for( i = 0; i < 2; i++ ){
				next = num + (j[i]*bitset<32>(num).count());
				//cout<<num<<" "<<bitset<32>(num).count()<<endl;
				if( 0 < next && next <= N ){
					if( cost[next] == (int)mod ){
						cost[next] = cost[num]+1;
						Q.push( next );
						//cout<<next<<endl;
					}
					if( next == N ) flag = 1;
				}
			}
			//cout<<num<<" "<<cost[num]<<endl;
			if( flag ){
				ans = cost[N];
				break;
			}
			
			Q.pop();
		}
	}
	else{
		ans = 1;
	}
	if( cost[N] == (int)mod ) ans = -1;
	
	cout<<ans<<endl;
	
	
	return 0;
}
            
            
            
        