結果

問題 No.3 ビットすごろく
コンテスト
ユーザー ふやけももんが
提出日時 2025-11-25 15:24:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 679 bytes
コンパイル時間 1,912 ms
コンパイル使用メモリ 200,940 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-25 15:24:29
合計ジャッジ時間 3,429 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> able(n+1,-1);
    queue<pair<int,int>> que;

    que.push({1,1});
    while(!que.empty()){
        pair<int,int> check = que.front();
        que.pop();

        if(able[check.first] != -1){
            continue;
        }
        if(check.first <0 || check.first >n){
            continue;
        }
        
        able[check.first] = check.second;
        
        bitset<16> x = check.first;
        int diff = x.count();
        que.push({check.first-diff,check.second+1});
        que.push({check.first+diff,check.second+1});
    }

    cout << able[n] << endl;
    
    
}
0