結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-12 19:26:52 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,006 bytes |
| コンパイル時間 | 3,293 ms |
| コンパイル使用メモリ | 279,984 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-12 19:26:57 |
| 合計ジャッジ時間 | 4,876 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using Int = int64_t;
using uInt = uint64_t;
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
void solve( /* Copyright by Urtusea */ )
{
int n;
cin >> n;
vector<int> vis(n + 1);
queue<int> q;
q.push(vis[1] = 1);
while (!q.empty()) {
auto u = q.front(); q.pop();
int v = __popcount(u);
if (u + v <= n && !vis[u + v]) {
vis[u + v] = vis[u] + 1;
q.push(u);
}
if (u - v > 0 && !vis[u - v]) {
vis[u - v] = vis[u] + 1;
q.push(u);
}
}
if (vis[n]) {
cout << vis[n] << '\n';
} else {
cout << -1 << '\n';
}
}
int main(int argc, char *argv[], char *envp[])
{
cin.tie(nullptr)->sync_with_stdio(false);
// for (int i = 1, n = (cin >> n, n); i <= n; i++)
solve();
return 0;
}