結果

問題 No.1868 Teleporting Cyanmond
ユーザー kokatsukokatsu
提出日時 2022-03-11 21:35:28
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,309 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 2,630 ms
コンパイル使用メモリ 221,536 KB
実行使用メモリ 9,792 KB
最終ジャッジ日時 2023-09-04 16:20:15
合計ジャッジ時間 8,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1,309 ms
9,792 KB
testcase_04 AC 803 ms
8,480 KB
testcase_05 AC 5 ms
4,384 KB
testcase_06 AC 48 ms
4,380 KB
testcase_07 AC 266 ms
5,260 KB
testcase_08 AC 98 ms
4,716 KB
testcase_09 AC 232 ms
5,108 KB
testcase_10 AC 1,158 ms
7,248 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 88 ms
4,580 KB
testcase_13 AC 19 ms
4,872 KB
testcase_14 AC 37 ms
7,044 KB
testcase_15 AC 26 ms
5,872 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 33 ms
7,960 KB
testcase_19 AC 33 ms
8,948 KB
testcase_20 AC 33 ms
7,628 KB
testcase_21 AC 33 ms
8,360 KB
testcase_22 AC 33 ms
8,408 KB
testcase_23 AC 28 ms
8,088 KB
testcase_24 AC 29 ms
8,344 KB
testcase_25 AC 29 ms
8,412 KB
testcase_26 AC 28 ms
9,408 KB
testcase_27 AC 28 ms
7,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

struct S {
    int pos, cnt;
}

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

    auto R = readln.chomp.split.to!(int[]);

    int res;

    auto seen = new bool[](N);
    seen[0] = true;

    --N;
    R[] -= 1;

    auto heap = new BinaryHeap!(Array!S, "a.cnt == b.cnt ? a.pos < b.pos : a.cnt > b.cnt")();
    heap.insert(S(0, 0));
    while (!heap.empty) {
        auto f = heap.front;
        heap.popFront;

        if (f.pos == N) {
            res = f.cnt;
            break;
        }

        foreach (i; f.pos .. R[f.pos]+1) {
            if (!seen[i]) {
                heap.insert(S(i, f.cnt+1));
                seen[i] = true;
            }
        }
    }

    res.writeln;
}
0