結果

問題 No.1868 Teleporting Cyanmond
ユーザー ayataka5ayataka5
提出日時 2022-03-11 21:29:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,183 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 206,828 KB
実行使用メモリ 813,896 KB
最終ジャッジ日時 2023-10-14 06:17:14
合計ジャッジ時間 4,512 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> R(N);
    for(int i = 0; i < N-1; i++) cin >> R[i];
    vector<vector<int>> Graph(N);
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < R[i]; j++) {
            Graph[i].push_back(j);
        }
    }
    /*
    cout << "start" << endl;
    for(auto G : Graph) {
        for(auto g : G) {
            cout << " " << g;
        }
        cout << endl;
    }
    cout << " end " << endl;
    */
    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while(!que.empty()) {
        int v = que.front();
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : Graph[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
    cout << dist[N-1] << endl;
    return 0;
}
0