189952025-11-14 06:55:55birozsÜltetéspython3Time limit exceeded 0/75699ms4524 KiB
N = int(input())
T = list(map(int,input().split()))
sor = []
volt = []
hiba = 0
for i in range(N):
    if i+1 not in volt and T[i] not in volt:
        sor.append([i+1,T[i]])
        volt.append(i+1)
        volt.append(T[i])
    elif i+1 in volt and T[i] in volt:
        hiba += 1
    elif i+1 not in volt and T[i] in volt:
        Elol = False
        for j in range(len(sor)):
            if sor[j][0] == T[i]:
                Elol = True
                volt.append(i+1)
                sor[j] = [i+1] + sor[j]
                break
        if not Elol:
            sor.append([i+1])
            hiba += 1
    elif i+1 in volt and T[i] not in volt:
        Vegen = False
        for j in range(len(sor)):
            if sor[j][-1] == i+1:
                Vegen = True
                volt.append(T[i])
                sor[j].append(T[i])
                break
        if not Vegen:
            sor.append([T[i]])
            hiba += 1
print(N-hiba)
szekrend = [0] * (N+1)
szek = 0
for resz in sor:
    for k in resz:
        szek += 1
        szekrend[k] = szek
for i in range(1,N+1):
    print(szekrend[i],end=" ")       


    
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted16ms3124 KiB
2Time limit exceeded689ms4112 KiB
subtask20/5
3Wrong answer16ms3320 KiB
4Wrong answer17ms3032 KiB
5Wrong answer17ms3124 KiB
6Wrong answer16ms3312 KiB
7Wrong answer16ms3124 KiB
subtask30/5
8Wrong answer16ms3312 KiB
9Wrong answer16ms3036 KiB
10Wrong answer17ms3124 KiB
11Accepted17ms3124 KiB
12Wrong answer17ms3228 KiB
subtask40/5
13Wrong answer16ms3144 KiB
14Wrong answer17ms3232 KiB
15Wrong answer17ms3124 KiB
16Wrong answer17ms3124 KiB
17Wrong answer17ms3196 KiB
subtask50/10
18Wrong answer17ms3232 KiB
19Wrong answer48ms3380 KiB
20Wrong answer48ms3468 KiB
21Wrong answer48ms3324 KiB
22Wrong answer46ms3316 KiB
23Wrong answer17ms3124 KiB
24Wrong answer17ms3312 KiB
25Wrong answer50ms3308 KiB
26Time limit exceeded699ms4256 KiB
27Time limit exceeded681ms4148 KiB
subtask60/10
28Wrong answer48ms3380 KiB
29Wrong answer142ms3636 KiB
30Wrong answer291ms3636 KiB
31Wrong answer500ms3892 KiB
32Time limit exceeded685ms3636 KiB
33Time limit exceeded680ms3876 KiB
34Time limit exceeded685ms3884 KiB
35Time limit exceeded684ms3892 KiB
36Time limit exceeded683ms4524 KiB
37Time limit exceeded676ms4148 KiB
subtask70/40
38Wrong answer52ms3376 KiB
39Wrong answer165ms3636 KiB
40Wrong answer337ms3872 KiB
41Wrong answer574ms3892 KiB
42Time limit exceeded685ms3636 KiB
43Time limit exceeded680ms3892 KiB
44Time limit exceeded677ms3892 KiB
45Time limit exceeded688ms4152 KiB
46Time limit exceeded675ms4148 KiB
47Time limit exceeded684ms4400 KiB
48Time limit exceeded679ms4400 KiB
49Time limit exceeded686ms4404 KiB
50Time limit exceeded677ms4400 KiB
51Time limit exceeded684ms4400 KiB
52Time limit exceeded681ms4400 KiB
53Time limit exceeded686ms4400 KiB
54Time limit exceeded680ms4392 KiB
55Time limit exceeded685ms4400 KiB
56Time limit exceeded679ms4388 KiB
57Time limit exceeded683ms4404 KiB