結果

問題 No.3 ビットすごろく
ユーザー ForestedForested
提出日時 2020-05-25 15:16:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 835 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 94,696 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-13 02:04:31
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

constexpr int INF = 1e9;
int N;
vector<int> ans;

int GO(int x) {
    int res = 0;
    while (x) {
        res += x % 2;
        x /= 2;
    }
    return res;
}

int searchf(int x) {
    if (x <= 0 || N < x) return INF;
    if (x == N) return 1;
    if (ans[x] != -1) return ans[x];
    ans[x] = INF;
    int res = min(searchf(x + GO(x)), searchf(x - GO(x))) + 1;
    ans[x] = res;
    return res;
}

int main() {
    cin >> N;
    ans = vector<int>(N + 1, -1);
    if (searchf(1) >= INF) cout << -1 << endl;
    else cout << searchf(1) << endl;
}
0