結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2019-01-08 00:38:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 606 bytes |
コンパイル時間 | 1,615 ms |
コンパイル使用メモリ | 172,480 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-01 09:12:28 |
合計ジャッジ時間 | 2,636 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; queue<int> que; vector<int> dst(n + 1, -1); que.push(1); dst[1] = 1; int crr = 1; int nxt; while(!que.empty()) { crr = que.front(); que.pop(); int dif = bitset<32> (crr).count(); nxt = crr + dif; if (nxt <= n && dst[nxt] == -1) { que.push(nxt); dst[nxt] = dst[crr] + 1; } nxt = crr - dif; if (0 < nxt && dst[nxt] == -1) { que.push(nxt); dst[nxt] = dst[crr] + 1; } } cout << dst[n] << '\n'; return 0; }