結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-08-19 02:11:35 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,069 bytes |
コンパイル時間 | 1,839 ms |
コンパイル使用メモリ | 167,980 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 08:48:03 |
合計ジャッジ時間 | 2,414 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
コンパイルメッセージ
main.cpp:17:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 17 | main(){ | ^~~~
ソースコード
#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; }