結果

問題 No.3 ビットすごろく
ユーザー kpinkcat
提出日時 2023-10-05 10:10:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 1,610 ms
コンパイル使用メモリ 197,736 KB
最終ジャッジ日時 2025-02-17 04:22:59
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<iostream>
#include<map>
#include<vector>
#include <algorithm>
#include<math.h>
#include <iomanip>
#include<set>
#include <numeric>
#include<string>
using ll = long long;
using namespace std;

int main(){
    int n, now = 1;
    cin >> n;
    set<int> st;
    while (now != n){
        int tmp, cnt = 0;
        if (st.count(now)){
            cout << -1 << endl;
            return 0;
        }
        st.insert(now);
        tmp = now;
        while (tmp){
            if (tmp &1) cnt++;
            tmp >>= 1;
        }
        if (now + cnt == n){
            st.insert(n);
            break;
        } else if (now + cnt > n) now -= cnt;
        else now += cnt;
    }
    cout << st.size() << endl;
}
0