結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
mine691
|
| 提出日時 | 2018-07-06 14:31:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 636 bytes |
| コンパイル時間 | 707 ms |
| コンパイル使用メモリ | 77,460 KB |
| 実行使用メモリ | 10,140 KB |
| 最終ジャッジ日時 | 2024-07-01 02:45:35 |
| 合計ジャッジ時間 | 13,119 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 32 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int INF = 1e9;
int bfs(int n) {
queue<int> q;
q.push(1);
vector<int> root(n + 1, INF);
root[1] = 1;
while (q.size())
{
int now = q.front();
q.pop();
int next = __builtin_popcount(now);
if (now - next > 0 && root[now - next] == INF)
{
root[next] = now + 1;
q.emplace(now - next);
}
if (now + next <= n && root[now + next] == INF)
{
root[next] == now + 1;
q.emplace(now + next);
}
}
if (root[n] == INF)
return -1;
else
return root[n];
}
int main() {
int n;
cin >> n;
cout << bfs(n) << endl;
}
mine691