4092 | 2023-03-13 21:30:05 | Szin Attila | Mágikus sorozat | cpp14 | Accepted 100/100 | 193ms | 96612 KiB |
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;
const int maxN = 2e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
int main() {
InTheNameOfGod;
int n;
cin >> n;
vector<int> v(n);
for(int &i : v) cin >> i;
vector<vector<int> > g(n+1);
vector<int> be(n, 0), mo(n, -1);
for(int i = 1; i < n; i++) {
g[v[i]].push_back(i+v[i]);
}
priority_queue<pair<int, int> > q;
for(int i = 0; i < n; i++) {
q.push({-1, -i});
}
vector<set<int> > no(n);
while(!q.empty()) {
pair<int, int> cur = q.top();
q.pop();
int x = -cur.second, val = -cur.first;
if(no[x].find(val) != no[x].end() || mo[x] != -1) continue;
mo[x] = val;
for(int sz : g[x]) {
if(mo[sz] == -1) {
no[sz].insert(val);
q.push({-val-1, -sz});
}
}
}
for(int i : mo) cout << i << ' ';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1700 KiB | ||||
2 | Accepted | 8ms | 4848 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 4ms | 2948 KiB | ||||
4 | Accepted | 4ms | 3160 KiB | ||||
5 | Accepted | 4ms | 3372 KiB | ||||
subtask3 | 15/15 | ||||||
6 | Accepted | 3ms | 2860 KiB | ||||
7 | Accepted | 3ms | 3096 KiB | ||||
8 | Accepted | 2ms | 3012 KiB | ||||
9 | Accepted | 2ms | 3004 KiB | ||||
10 | Accepted | 3ms | 3136 KiB | ||||
subtask4 | 30/30 | ||||||
11 | Accepted | 4ms | 4156 KiB | ||||
12 | Accepted | 4ms | 4392 KiB | ||||
13 | Accepted | 4ms | 4320 KiB | ||||
14 | Accepted | 4ms | 4200 KiB | ||||
subtask5 | 40/40 | ||||||
15 | Accepted | 180ms | 92712 KiB | ||||
16 | Accepted | 182ms | 92644 KiB | ||||
17 | Accepted | 165ms | 75036 KiB | ||||
18 | Accepted | 136ms | 64116 KiB | ||||
19 | Accepted | 144ms | 63876 KiB | ||||
20 | Accepted | 156ms | 73312 KiB | ||||
21 | Accepted | 165ms | 73480 KiB | ||||
22 | Accepted | 165ms | 73468 KiB | ||||
23 | Accepted | 165ms | 73900 KiB | ||||
24 | Accepted | 193ms | 87428 KiB | ||||
25 | Accepted | 171ms | 73748 KiB | ||||
26 | Accepted | 160ms | 74320 KiB | ||||
27 | Accepted | 180ms | 80144 KiB | ||||
28 | Accepted | 179ms | 94948 KiB | ||||
29 | Accepted | 179ms | 94176 KiB | ||||
30 | Accepted | 130ms | 77468 KiB | ||||
31 | Accepted | 158ms | 85280 KiB | ||||
32 | Accepted | 164ms | 96612 KiB |