結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2019-01-08 00:34:58 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 583 bytes |
コンパイル時間 | 1,330 ms |
コンパイル使用メモリ | 162,388 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 00:31:49 |
合計ジャッジ時間 | 2,367 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 21 |
ソースコード
#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()) { 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; }