結果

問題 No.3 ビットすごろく
ユーザー char134217728char134217728
提出日時 2017-08-19 02:11:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,069 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 153,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 00:47:53
合計ジャッジ時間 2,517 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:17:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
 main(){
      ^

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;

si y;
queue<int> q[2];
int n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int count = 1;
  q[1].push(1);
  y.insert(1);
  while(true){
    int b = count % 2;
    if(q[b].empty())break;
    while(!q[b].empty()){
      int tmp = q[b].front();
      q[b].pop();
      if(tmp == n){
        cout << count << endl;
        return 0;
      }
      int bc = 0, _tmp = tmp;
      while(_tmp > 0){
        if(_tmp & 1)bc++;
        _tmp >>= 1;
      }
      if(tmp - bc >  0 && y.find(tmp - bc) == y.end()){
        q[1-b].push(tmp - bc);
        y.insert(tmp - bc);
      }
      if(tmp + bc <= n && y.find(tmp + bc) == y.end()){
        q[1-b].push(tmp + bc);
        y.insert(tmp + bc);
      }
    }
    count++;
  }
  cout << -1 << endl;
  return 0;
}
0