結果

問題 No.3 ビットすごろく
ユーザー nukachanukacha
提出日時 2017-02-25 10:15:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,250 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 72,884 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 18:52:02
合計ジャッジ時間 2,956 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdlib>

std::vector<int> m;
std::vector<int> d;
int n;
int max;

void move(int now, int count) {
    int s, e;
    if (count >= d[now-1] && d[now-1] != -1) {
        return;
    } else {
        d[now-1] = count;
    }
    if (now == 1) {
        return;
    }
    if (now - 1 - max < 0) {
        s = 0;
    } else {
        s = now - 1 - max;
    }
    if (now - 1 + max > n) {
        e = n;
    } else {
        e = now - 1 + max;
    }
    for (int i = s; i < e; i++) {
        if (abs(now - i - 1) == m[i]) {
            move(i+1, count+1);
        }
    }
}

int main() {
    std::cin >> n;
    d.clear();
    d.resize(n, -1);
    m.clear();
    m.resize(n, 0);   // (i+1) -> binary としたときの1の数
    std::vector<bool> f(n, false);  // 到達したらtrue
    max = 0;
    for (int i = 0; i < n; i++) {
        int tmp = i + 1;
        while (tmp != 0) {
            if (tmp % 2 == 1) {
                m[i]++;
            }
            tmp /= 2;
            if (m[tmp-1] != 0) {
                m[i] += m[tmp-1];
                break;
            }
        }
        if (max < m[i]) {
            max = m[i];
        }
    }

    move(n, 1);
    std::cout << d[0] << std::endl;
}
0