結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-27 15:44:36 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 717 bytes |
| 記録 | |
| コンパイル時間 | 1,130 ms |
| コンパイル使用メモリ | 220,756 KB |
| 実行使用メモリ | 9,260 KB |
| 最終ジャッジ日時 | 2026-07-06 05:00:11 |
| 合計ジャッジ時間 | 3,200 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
| 外部呼び出し有り |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
vector<bool> seen(n+1,false);
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.at(a)) continue;
seen.at(a)=true;
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"); }