結果

問題 No.3 ビットすごろく
コンテスト
ユーザー 👑 ONPU3
提出日時 2026-10-14 21:49:44
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 4 ms / 5,000 ms
+ 76µs
コード長 613 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,433 ms
コンパイル使用メモリ 347,924 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-10-14 21:49:51
合計ジャッジ時間 4,893 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;cin>>n;
    queue<ll>que;
    map<ll,ll>dist;
    que.push(1);
    dist[1]=1;
    while(!que.empty())
    {
        ll now=que.front();
        que.pop();
        ll d=__builtin_popcount(now);
        for(int i=-1;i<=1;i+=2)
        {
            ll nex=now+d*i;
            if(nex<=0||nex>n||dist.contains(nex))continue;
            dist[nex]=dist[now]+1;
            que.push(nex);
        }
    }
    if(dist.contains(n))cout<<dist[n]<<endl;
    else cout<<-1<<endl;
}
0