結果

問題 No.3 ビットすごろく
コンテスト
ユーザー あおこう
提出日時 2023-07-02 22:35:40
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,363 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,125 ms
コンパイル使用メモリ 203,384 KB
最終ジャッジ日時 2026-07-01 14:26:58
合計ジャッジ時間 1,807 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:76,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:62,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bit: In instantiation of 'constexpr int std::__popcount(_Tp) [with _Tp = long long int]':
main.cpp:56:27:   required from here
   56 |         ll bi = __popcount(p);
      |                 ~~~~~~~~~~^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bit:308:34: error: argument 1 in call to function '__builtin_popcountg' has signed type
  308 |       return __builtin_popcountg(__x);
      |                                  ^~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, r) for(int i = 0; i < (r); ++i)
#define reps(i, s, r) for(int i = (s); i < (r); ++i)
#define fore(i, m2) for(auto &i : m2)
#define vi vector<int>
#define vl vector<ll>
#define pl pair<ll, ll>
#define all(i) (i).begin(), (i).end()
#define fs first
#define sc second

template <class T> bool chmin(T &i, T b) {
    if(i > b) {
        i = b;
        return true;
    }
    return false;
}
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll INF = LONG_LONG_MAX / 3;
const ll MOD = 1'000'000'007;
const ll MAX = 2e5 + 5;

int main() {

    ll n = 0, ans = INF;
    cin >> n;
    vl dp(n + 5), seen(n + 5);

    queue<pl> q;
    q.push({1, 1});

    while(!q.empty()) {
        ll p, d;
        tie(p, d) = q.front();
        q.pop();

        if(p == n) {
            chmin(ans, d);
        }

        dp[p] = d;
        seen[p] = 1;
        ll bi = __popcount(p);

        if(p - bi > 0 && !seen[p - bi]) {
            seen[p - bi] = 1;
            q.push({p - bi, d + 1});
        }

        if(p + bi <= n && !seen[p + bi]) {
            seen[p + bi] = 1;
            q.push({p + bi, d + 1});
        }
    }

    if(ans == INF)
        ans = -1;

    cout << ans << endl;
}
0