52462023-04-23 21:07:23nmarciMágikus sorozatcpp11Wrong answer 15/100137ms16012 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

const ll mod = 1e9 + 7;

int z[300100], a[300100];

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> z[i];
    }
    a[1] = 1;
    int index = 0, maxind = 0;
    for(int i = 2; i <= n; ++i){
        if(z[i] > 0){
            maxind = z[i] + 1;
            index = 1;
        }
        if(index > 0){
            a[i] = a[index];
            ++index;
            if(index == maxind){
                index = 0;
            }
        }
        else{
            if(a[maxind] == 2){
                a[i] = 3;
            }
            else{
                a[i] = 2;
            }
            maxind = 0;
        }
    }
    for(int i = 1; i <= n; ++i){
        cout << a[i] << " ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2164 KiB
2Accepted6ms2392 KiB
subtask215/15
3Accepted4ms2556 KiB
4Accepted4ms2928 KiB
5Accepted4ms2888 KiB
subtask30/15
6Accepted3ms3020 KiB
7Accepted3ms3148 KiB
8Accepted3ms3408 KiB
9Accepted3ms3416 KiB
10Wrong answer3ms3612 KiB
subtask40/30
11Wrong answer4ms3724 KiB
12Accepted3ms3736 KiB
13Wrong answer3ms3740 KiB
14Wrong answer3ms3996 KiB
subtask50/40
15Accepted90ms9348 KiB
16Wrong answer90ms10040 KiB
17Wrong answer93ms10932 KiB
18Wrong answer97ms11804 KiB
19Wrong answer107ms13036 KiB
20Wrong answer112ms14280 KiB
21Wrong answer118ms15408 KiB
22Wrong answer114ms15736 KiB
23Wrong answer115ms15684 KiB
24Wrong answer93ms15684 KiB
25Wrong answer97ms15688 KiB
26Wrong answer104ms16012 KiB
27Wrong answer82ms15424 KiB
28Accepted96ms15968 KiB
29Accepted93ms15968 KiB
30Accepted137ms15968 KiB
31Accepted116ms15960 KiB
32Accepted100ms15896 KiB