結果
問題 | No.1868 Teleporting Cyanmond |
ユーザー | milanis48663220 |
提出日時 | 2022-03-11 21:25:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 2,202 bytes |
コンパイル時間 | 1,411 ms |
コンパイル使用メモリ | 127,460 KB |
実行使用メモリ | 18,092 KB |
最終ジャッジ日時 | 2023-10-14 06:08:20 |
合計ジャッジ時間 | 3,367 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | AC | 1 ms
4,352 KB |
testcase_03 | AC | 42 ms
16,088 KB |
testcase_04 | AC | 27 ms
12,524 KB |
testcase_05 | AC | 3 ms
4,348 KB |
testcase_06 | AC | 8 ms
5,368 KB |
testcase_07 | AC | 23 ms
9,552 KB |
testcase_08 | AC | 14 ms
7,164 KB |
testcase_09 | AC | 19 ms
8,868 KB |
testcase_10 | AC | 41 ms
15,256 KB |
testcase_11 | AC | 2 ms
4,352 KB |
testcase_12 | AC | 12 ms
6,456 KB |
testcase_13 | AC | 22 ms
9,832 KB |
testcase_14 | AC | 43 ms
16,444 KB |
testcase_15 | AC | 29 ms
12,124 KB |
testcase_16 | AC | 6 ms
4,576 KB |
testcase_17 | AC | 10 ms
5,980 KB |
testcase_18 | AC | 41 ms
17,892 KB |
testcase_19 | AC | 40 ms
17,768 KB |
testcase_20 | AC | 40 ms
17,888 KB |
testcase_21 | AC | 40 ms
18,092 KB |
testcase_22 | AC | 40 ms
17,800 KB |
testcase_23 | AC | 38 ms
18,012 KB |
testcase_24 | AC | 38 ms
17,764 KB |
testcase_25 | AC | 38 ms
17,812 KB |
testcase_26 | AC | 39 ms
17,820 KB |
testcase_27 | AC | 38 ms
17,832 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const ll INF = 1e+15; typedef pair<ll, int> P; struct edge{ int to; ll cost; }; vector<ll> dijkstra(int s, vector<vector<edge>> G){ priority_queue<P, vector<P>, greater<P>> que; int n = G.size(); vector<ll> d(n, INF); d[s] = 0; que.push(P(0, s)); while(!que.empty()){ P p = que.top();que.pop(); int v = p.second; if(d[v] < p.first) continue; for(int i = 0; i < G[v].size(); i++){ edge e = G[v][i]; if(d[v] + e.cost < d[e.to]){ d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } return d; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector<vector<edge>> g(n); for(int i = 1; i < n; i++){ g[i].push_back(edge{i-1, 0}); } for(int i = 0; i < n-1; i++){ int r; cin >> r; r--; g[i].push_back(edge{r, 1}); } cout << dijkstra(0, g)[n-1] << endl; }