結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-12-19 13:24:21 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 871 bytes |
| コンパイル時間 | 3,463 ms |
| コンパイル使用メモリ | 279,608 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-19 13:24:27 |
| 合計ジャッジ時間 | 5,105 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#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<int> vis(n + 1, -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] == -1) {
q.emplace(v1);
vis[v1] = vis[u] + 1;
}
if (v2 >= 1 && vis[v2] == -1) {
q.emplace(v2);
vis[v2] = vis[u] + 1;
}
}
std::cout << vis[n] << '\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;
}