結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2024-11-27 14:49:02 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 719 bytes |
コンパイル時間 | 4,812 ms |
コンパイル使用メモリ | 164,656 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-27 14:49:08 |
合計ジャッジ時間 | 4,125 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
#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_front({a-bitCount(a),b+1}); } if(a+bitCount(a)<=n){ dq.push_front({a+bitCount(a),b+1}); } } cout << -1 << endl; } int main() { solve();system("pause"); }