結果

問題 No.1868 Teleporting Cyanmond
ユーザー baLoon8128baLoon8128
提出日時 2022-03-18 19:51:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,140 bytes
コンパイル時間 4,312 ms
コンパイル使用メモリ 232,124 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-04-14 07:26:55
合計ジャッジ時間 6,861 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 39 ms
8,320 KB
testcase_04 AC 29 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 8 ms
6,940 KB
testcase_07 AC 20 ms
6,940 KB
testcase_08 AC 13 ms
6,940 KB
testcase_09 AC 18 ms
6,944 KB
testcase_10 AC 37 ms
7,936 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 11 ms
6,940 KB
testcase_13 AC 21 ms
6,940 KB
testcase_14 AC 42 ms
8,704 KB
testcase_15 AC 29 ms
6,944 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 10 ms
6,944 KB
testcase_18 AC 45 ms
9,088 KB
testcase_19 AC 46 ms
9,216 KB
testcase_20 AC 44 ms
9,088 KB
testcase_21 AC 45 ms
9,216 KB
testcase_22 AC 45 ms
9,216 KB
testcase_23 AC 44 ms
9,088 KB
testcase_24 AC 45 ms
9,088 KB
testcase_25 AC 45 ms
9,088 KB
testcase_26 AC 44 ms
9,200 KB
testcase_27 AC 45 ms
9,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:34:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   34 |         for (auto [t, c] : g[v]) {
      |                   ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)

int main() {
    const int INF = 1001001001;
    int n;
    cin >> n;
    vector<vector<pii>> g(n, vector<pii>(0));
    rep(i, n - 1) g[i + 1].emplace_back(i, 0);
    rep(i, n - 1) {
        int r;
        cin >> r;
        r--;
        g[i].emplace_back(r, 1);
    }

    vi ret(n, INF);
    deque<pii> dq;
    dq.emplace_back(0, 0);
    ret[0] = 0;
    while (dq.size()) {
        int v, d;
        tie(v, d) = dq.front();
        dq.pop_front();
        if (d > ret[v]) continue;
        for (auto [t, c] : g[v]) {
            if (d + c < ret[t]) {
                ret[t] = d + c;
                if (c == 0) {
                    dq.emplace_front(t, d);
                } else {
                    dq.emplace_back(t, d + c);
                }
            }
        }
    }
    cout << ret[n - 1] << endl;
    return 0;
}
0