結果

問題 No.3 ビットすごろく
コンテスト
ユーザー naimonon77
提出日時 2016-02-29 05:20:57
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 775 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 895 ms
コンパイル使用メモリ 182,524 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-04-11 17:18:33
合計ジャッジ時間 3,156 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21 WA * 1 RE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <queue>
using namespace std;
#define MAX 10005
struct Node{
  int x,cnt;
};
int main() {
  int N;
  cin >> N;
  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 = __builtin_popcount(now.x);
    int rear = now.x + plus;
    int ex = now.x - plus;
    if(not visited[rear] and rear > 0) {
      Node node_r = {rear,now.cnt+1};
      visited[rear] = true;
      q.push(node_r);
    }
    if( not visited[ex] && ex < N) {
      Node node_ex = {ex,now.cnt+1};
      visited[ex] = true;
      q.push(node_ex);
    }
    if(rear == N) {
      ans = now.cnt+1; break;
    }
  }
  cout << ans << endl;
  return 0;
}
0