結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
sntea
|
| 提出日時 | 2015-08-26 19:33:14 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,067 bytes |
| コンパイル時間 | 861 ms |
| コンパイル使用メモリ | 88,404 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-01 07:29:36 |
| 合計ジャッジ時間 | 1,630 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <utility>
#define endl '\n'
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef pair<int,int> P;
typedef long long int LL;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin>>N;
vector<bool> flag(N,true);
queue<P> que;
int ans=-1;
que.push(P(1,1));
while(!que.empty()){
P p=que.front();
que.pop();
if(p.second==N){
ans=p.first;
break;
}
int n=log2(p.second)+1;
int dp=0;
REP(i,n){
dp+=(p.second>>i&1);
}
if(p.second+dp<=N&&flag[p.second+dp-1]){
flag[p.second+dp-1]=false;
que.push(P(p.first+1,p.second+dp));
}
if(p.second-dp>=1&&flag[p.second-dp-1]){
flag[p.second-dp-1]=false;
que.push(P(p.first+1,p.second-dp));
}
}
cout<<ans<<endl;
return 0;
}
sntea