結果

問題 No.3 ビットすごろく
ユーザー WagiHOH
提出日時 2016-07-08 10:18:30
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 925 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 98,436 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 03:37:16
合計ジャッジ時間 1,577 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import core.bitop;


struct Block
{
    uint bits;
    bool forward, backward;
    uint optimum = -1;
}


void main()
{
    immutable n = readln.chomp.to!uint;
    auto game = new Block[n + 1];
    foreach (i, ref x; game) x.bits = i.popcnt;
    uint[] route = [1];
    while (!route.empty) {
        auto point = route.back;
        if (point < 1 || point > n) {
            route.popBack;
            continue;
        }
        with (game[point]) {
            optimum = min(route.length, optimum);
            if (!forward) {
                route ~= point + bits;
                forward = true;
            } else if (!backward) {
                route ~= point - bits;
                backward = true;
            } else {
                route.popBack;
            }
        }
    }
    writeln(cast(int)game[n].optimum);
}
0