結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
mine691
|
| 提出日時 | 2018-07-06 14:31:35 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 636 bytes |
| 記録 | |
| コンパイル時間 | 641 ms |
| コンパイル使用メモリ | 96,240 KB |
| 実行使用メモリ | 943,524 KB |
| 最終ジャッジ日時 | 2026-03-21 19:39:20 |
| 合計ジャッジ時間 | 189,432 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 TLE * 3 MLE * 29 |
ソースコード
#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