結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-05-03 00:02:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 562 bytes |
コンパイル時間 | 512 ms |
コンパイル使用メモリ | 64,552 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 07:50:55 |
合計ジャッジ時間 | 1,465 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <iostream> #include <queue> using namespace std; const int INF = 1000000; int N; int d[10001]; int main() { cin >> N; for (int i = 0; i <= 10000; i++) { d[i] = INF; } queue<int> que; d[1] = 1; que.push(1); while (!que.empty()) { int n = que.front(); que.pop(); int bn = __builtin_popcount(n); if (n - bn >= 1 && d[n - bn] == INF) { d[n - bn] = d[n] + 1; que.push(n - bn); } if (n + bn <= N && d[n + bn] == INF) { d[n + bn] = d[n] + 1; que.push(n + bn); } } cout << (d[N] != INF ? d[N] : -1) << endl; return 0; }