53072023-04-25 18:58:04anonMágikus sorozatcpp17Accepted 100/100156ms81884 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;
}

SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1808 KiB
2Accepted7ms3356 KiB
subtask215/15
3Accepted4ms2684 KiB
4Accepted4ms3140 KiB
5Accepted4ms3428 KiB
subtask315/15
6Accepted3ms2728 KiB
7Accepted3ms2936 KiB
8Accepted3ms3144 KiB
9Accepted3ms3356 KiB
10Accepted3ms3568 KiB
subtask430/30
11Accepted4ms3876 KiB
12Accepted4ms4024 KiB
13Accepted4ms4336 KiB
14Accepted3ms4304 KiB
subtask540/40
15Accepted115ms49028 KiB
16Accepted112ms49216 KiB
17Accepted125ms62532 KiB
18Accepted153ms81884 KiB
19Accepted150ms78216 KiB
20Accepted144ms65864 KiB
21Accepted137ms52692 KiB
22Accepted136ms49696 KiB
23Accepted134ms50744 KiB
24Accepted116ms51664 KiB
25Accepted123ms51792 KiB
26Accepted128ms52080 KiB
27Accepted128ms63732 KiB
28Accepted119ms55112 KiB
29Accepted112ms51044 KiB
30Accepted156ms46828 KiB
31Accepted134ms46828 KiB
32Accepted115ms46824 KiB