結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
mine691
|
| 提出日時 | 2018-07-06 14:27:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 752 bytes |
| コンパイル時間 | 674 ms |
| コンパイル使用メモリ | 78,232 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 02:44:57 |
| 合計ジャッジ時間 | 1,706 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 23 |
ソースコード
#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];
while (q.size())
{
int now = q.front();
q.pop();
int next = __builtin_popcount(now);
if (now - next > 0 && root[next] == INF)
{
root[next] = now + 1;
q.push(now - next);
}
if (now + next <= n && root[next] == INF)
{
root[next] == now + 1;
q.push(now + next);
}
}
if (root[n] == INF)
return -1;
else
return root[n];
}
int main()
{
int n;
cin >> n;
cout << bfs(n) << endl;
}
mine691