結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2019-06-24 21:24:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 667 bytes |
コンパイル時間 | 1,558 ms |
コンパイル使用メモリ | 170,880 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 09:23:13 |
合計ジャッジ時間 | 2,534 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <iostream> #include<queue> #include <bits/stdc++.h> using namespace std; typedef long long ll; ll dis[100000]; int main(){ int N; cin>>N; queue<int> q;q.push(1); dis[1] = 1; while(!q.empty()){ int x = q.front(); q.pop(); bitset<32> bs(x); int v = bs.count(); int next_dis = x + v; int pre_dis = x - v; if(next_dis<=N && dis[next_dis]==0){ dis[next_dis] = dis[x] + 1; q.push(next_dis); } if(pre_dis<=N && dis[pre_dis]==0){ dis[pre_dis] = dis[x] + 1; q.push(pre_dis); } } cout<<(dis[N]?dis[N]:-1)<<endl; }