5307 | 2023-04-25 18:58:04 | anon | Mágikus sorozat | cpp17 | Accepted 100/100 | 156ms | 81884 KiB |
#include <vector>
#include <unordered_set>
#include <iostream>
using ll = long long;
using namespace std;
int main()
{
ll i, j, k, N;
cin >> N;
vector<ll> z(N + 1);
for(i = 1; i <= N; i++)
cin >> z[i];
vector<ll> a(N + 1);
a[1] = 1;
vector<unordered_set<ll>> bads(N + 2);
i = 2;
while(i <= N)
{
if(z[i])
{
j = i;
k = i + z[i];
for(;i < k && (i == j || !z[i]); i++)
a[i] = a[i - j + 1];
if(a[k - j + 1] > 1)
bads[k].insert(a[k - j + 1]);
}
else
{
a[i] = 2;
while(bads[i].find(a[i]) != bads[i].end())
a[i]++;
i++;
}
}
for(i = 1; i <= N; i++)
cout << a[i] << ' ';
cout << endl;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1808 KiB | ||||
2 | Accepted | 7ms | 3356 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 4ms | 2684 KiB | ||||
4 | Accepted | 4ms | 3140 KiB | ||||
5 | Accepted | 4ms | 3428 KiB | ||||
subtask3 | 15/15 | ||||||
6 | Accepted | 3ms | 2728 KiB | ||||
7 | Accepted | 3ms | 2936 KiB | ||||
8 | Accepted | 3ms | 3144 KiB | ||||
9 | Accepted | 3ms | 3356 KiB | ||||
10 | Accepted | 3ms | 3568 KiB | ||||
subtask4 | 30/30 | ||||||
11 | Accepted | 4ms | 3876 KiB | ||||
12 | Accepted | 4ms | 4024 KiB | ||||
13 | Accepted | 4ms | 4336 KiB | ||||
14 | Accepted | 3ms | 4304 KiB | ||||
subtask5 | 40/40 | ||||||
15 | Accepted | 115ms | 49028 KiB | ||||
16 | Accepted | 112ms | 49216 KiB | ||||
17 | Accepted | 125ms | 62532 KiB | ||||
18 | Accepted | 153ms | 81884 KiB | ||||
19 | Accepted | 150ms | 78216 KiB | ||||
20 | Accepted | 144ms | 65864 KiB | ||||
21 | Accepted | 137ms | 52692 KiB | ||||
22 | Accepted | 136ms | 49696 KiB | ||||
23 | Accepted | 134ms | 50744 KiB | ||||
24 | Accepted | 116ms | 51664 KiB | ||||
25 | Accepted | 123ms | 51792 KiB | ||||
26 | Accepted | 128ms | 52080 KiB | ||||
27 | Accepted | 128ms | 63732 KiB | ||||
28 | Accepted | 119ms | 55112 KiB | ||||
29 | Accepted | 112ms | 51044 KiB | ||||
30 | Accepted | 156ms | 46828 KiB | ||||
31 | Accepted | 134ms | 46828 KiB | ||||
32 | Accepted | 115ms | 46824 KiB |