結果

問題 No.3 ビットすごろく
ユーザー ForestedForested
提出日時 2020-05-25 15:16:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 835 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 93,940 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 03:44:13
合計ジャッジ時間 1,861 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
5,376 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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