結果

問題 No.3 ビットすごろく
ユーザー kokatsu
提出日時 2021-09-27 00:48:22
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 996 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 218,420 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 12:39:12
合計ジャッジ時間 2,795 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;
import core.bitop;

struct Sugoroku {
    int pos;
    int cnt;
}

void main() {
    int N;
    readf("%d\n", N);

    auto heap = new BinaryHeap!(Array!Sugoroku, "a.cnt > b.cnt")();
    heap.insert(Sugoroku(1, 1));

    auto passed = new bool[](N+1);
    passed[0..2] = true;

    int res = int.max;

    while (!heap.empty) {
        Sugoroku sugoroku = heap.front;
        heap.popFront;

        int forward = sugoroku.pos + sugoroku.pos.popcnt;
        if (forward == N) {
            res = min(res, sugoroku.cnt+1);
        }
        else if (forward < N && !passed[forward]) {
            passed[forward] = true;
            heap.insert(Sugoroku(forward, sugoroku.cnt+1));
        }

        int backward = sugoroku.pos - sugoroku.pos.popcnt;
        if (backward >= 1 && !passed[backward]) {
            passed[backward] = true;
            heap.insert(Sugoroku(backward, sugoroku.cnt+1));
        }
    }

    if (res == int.max) {
        res = -1;
    }

    res.writeln;
}
0