結果

問題 No.3 ビットすごろく
ユーザー IlagIlag
提出日時 2020-06-15 19:46:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 5,000 ms
コード長 674 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 165,448 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 01:45:50
合計ジャッジ時間 5,514 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 15 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 64 ms
4,380 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 41 ms
4,376 KB
testcase_09 AC 106 ms
4,376 KB
testcase_10 AC 149 ms
4,376 KB
testcase_11 AC 89 ms
4,380 KB
testcase_12 AC 60 ms
4,376 KB
testcase_13 AC 11 ms
4,376 KB
testcase_14 AC 141 ms
4,380 KB
testcase_15 AC 216 ms
4,376 KB
testcase_16 AC 187 ms
4,376 KB
testcase_17 AC 210 ms
4,376 KB
testcase_18 AC 8 ms
4,384 KB
testcase_19 AC 222 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 144 ms
4,380 KB
testcase_23 AC 221 ms
4,380 KB
testcase_24 AC 221 ms
4,376 KB
testcase_25 AC 216 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 13 ms
4,376 KB
testcase_28 AC 180 ms
4,376 KB
testcase_29 AC 92 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 79 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int nums[11111];
int dist[11111];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        nums[i] = __builtin_popcount(i);
    }
    for (int i = 0; i < 11111; i++) dist[i] = INF;
    dist[1] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            if (j - nums[j] > 0) dist[j - nums[j]] = min(dist[j - nums[j]], dist[j] + 1);
            if (j + nums[j] < n + 1) dist[j + nums[j]] = min(dist[j + nums[j]], dist[j] + 1);
        }
    }
    cout << (dist[n] == INF ? -1 : dist[n]) << endl;
}
0