結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-02 15:51:22 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| + 525µs | |
| コード長 | 952 bytes |
| 記録 | |
| コンパイル時間 | 2,418 ms |
| コンパイル使用メモリ | 336,332 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-09-02 15:51:44 |
| 合計ジャッジ時間 | 3,999 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int n;
bool vis[20005];
void solve()
{
cin>>n;
queue<array<int,2>>q;
q.push({1,1});
vis[1]=1;
while(!q.empty())
{
auto[c,d]=q.front();q.pop();
if(c==n)
{
cout<<d<<'\n';
return;
}
int f=c+__builtin_popcount(c),b=c-__builtin_popcount(c);
if(f<=n&&!vis[f])
{
q.push({f,d+1});
vis[f]=1;
}
if(b>1&&!vis[b])
{
q.push({b,d+1});
vis[b]=1;
}
}
cout<<"-1\n";
}
int main()
{
ios::sync_with_stdio(false);cin.tie(NULL);
int tc=1;
// cin>>tc;
while(tc--)solve();
return 0;
}