結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-04 11:49:46 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 560 bytes |
| コンパイル時間 | 4,175 ms |
| コンパイル使用メモリ | 162,548 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-14 09:19:26 |
| 合計ジャッジ時間 | 5,316 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int N; cin >> N; vector<int> dis(N+1, -1);
queue<int> Q; Q.emplace(1); dis[1] = 1;
while(!Q.empty())
{
int x = Q.front(); Q.pop();
if(x == N)
{
cout << dis[x] << endl;
return 0;
}
int p = __builtin_popcount(x);
for(int y: {x-p, x+p}) if(1 <= y && y <= N && dis[y] == -1)
{
dis[y] = dis[x] + 1; Q.push(y);
}
}
cout << -1 << endl;
}