結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-02-29 05:42:27 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,257 bytes | 
| コンパイル時間 | 1,364 ms | 
| コンパイル使用メモリ | 163,392 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-24 12:42:12 | 
| 合計ジャッジ時間 | 2,582 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 WA * 1 | 
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include "bits\stdc++.h"
#endif
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <list>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
#define VI vector<int>
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X) ((X)*(X))
#define MAX 10005
int pop_cnt(int x) {
  int cnt = 0;
  while(x) {
    if(x % 2) cnt++;
    x /= 2;
  }
  return cnt;
}
struct Node{
  int x,cnt;
};
int main() {
  int N;
  cin >> N;
  if(N == 1) cout << 1 << endl;
  int ans = -1;
  queue<Node> q;
  bool visited[MAX] = {0};
  Node tmp = {1,1};
  q.push(tmp);
  visited[1] = true;
  while( q.size() ) {
    Node now = q.front(); q.pop();
    int plus = pop_cnt(now.x);
    int rear = now.x + plus;
    int ex = now.x - plus;
    if(rear == N) {
      ans = now.cnt+1; break;
    }
    if( !visited[rear] && rear < N) {
      Node node_r = {rear,now.cnt+1};
      visited[rear] = true;
      q.push(node_r);
    }
    if( !visited[ex] && ex > 0) {
      Node node_ex = {ex,now.cnt+1};
      visited[ex] = true;
      q.push(node_ex);
    }
  }
  cout << ans << endl;
  return 0;
}
            
            
            
        