結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2024-11-27 15:53:41 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 713 bytes |
コンパイル時間 | 5,239 ms |
コンパイル使用メモリ | 165,504 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-27 15:53:49 |
合計ジャッジ時間 | 6,445 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
外部呼び出し有り |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef int64_t ll; ll bitCount(ll n){ ll res=0; while(n>0){ res+=n&1; n>>=1; } return res; } void solve() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; unordered_set<ll> seen; deque<pair<ll,ll>> dq; dq.push_back({1,1}); while(!dq.empty()){ auto [a,b]=dq.front(); dq.pop_front(); if(a==n){ cout << b << endl; return; } if(seen.count(a)) continue; seen.insert(a); if(a-bitCount(a)>=1){ dq.push_back({a-bitCount(a),b+1}); } if(a+bitCount(a)<=n){ dq.push_back({a+bitCount(a),b+1}); } } cout << -1 << endl; } int main() { solve();system("pause"); }