結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2024-12-19 13:20:04 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 866 bytes |
コンパイル時間 | 4,144 ms |
コンパイル使用メモリ | 280,184 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-19 13:20:11 |
合計ジャッジ時間 | 5,710 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 WA * 23 |
ソースコード
#include <bits/stdc++.h> #define int int32_t #define Int int64_t #define uint uint32_t #define uInt uint64_t void init() { } void code() { int n; std::cin >> n; std::vector<char> vis(n + 1); std::queue<int> q; vis[1] = 1; q.emplace(1); while (!q.empty()) { auto u = q.front(); q.pop(); int v1 = u + std::__popcount(u); int v2 = u - std::__popcount(u); if (v1 <= n && !vis[v1]) { q.emplace(v1); vis[v1] = vis[u] + 1; } if (v2 >= 1 && !vis[v2]) { q.emplace(v2); vis[v2] = vis[u] + 1; } } std::cout << (int)vis[n] - 1 << '\n'; } int main() { std::cin.tie(nullptr)->sync_with_stdio(false); // for (int i = 1, n = (std::cin >> n, n); i <= n; i++) { init(); code(); } return 0; }