結果
| 問題 | 
                            No.3 ビットすごろく
                             | 
                    
| コンテスト | |
| ユーザー | 
                             spade630
                         | 
                    
| 提出日時 | 2015-10-19 12:09:20 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 619 bytes | 
| コンパイル時間 | 730 ms | 
| コンパイル使用メモリ | 64,608 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-21 19:46:02 | 
| 合計ジャッジ時間 | 1,609 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 WA * 18 | 
ソースコード
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int INF = 1e+9;
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
 
 	int n;
 	cin >> n;
 	int ans = -1;
 	queue<int> que;
 	que.push(1);
 	bool visited[10001] = {0};
 	int d[10001] = {0};
 	d[1] = 1;
 	while(!que.empty()){
 		int p = que.front(); que.pop();
 		 
 		if(n == p){
 			ans = d[p];
 			break;
 		}
 		if(visited[p]){
 			continue;
 		}
 		visited[p] = true;
 		int next = __builtin_popcount(p);
 		if(next + p <= n){
 			d[next + p] = d[p] + 1;
 			que.push(next + p);
 		}
 	}
 	cout << ans << endl;
	return 0;
}
            
            
            
        
            
spade630