Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.031 s | 3 KBi |
#2 |
Correcto
|
0.024 s | 3 KBi |
#3 |
Correcto
|
0.029 s | 4 KBi |
#4 |
Correcto
|
0.027 s | 3 KBi |
#5 |
Correcto
|
0.033 s | 3 KBi |
#6 |
Correcto
|
0.246 s | 32 KBi |
#7 |
Correcto
|
0.25 s | 32 KBi |
#8 |
Correcto
|
0.02 s | 3 KBi |
#9 |
Correcto
|
0.029 s | 3 KBi |
#10 |
Correcto
|
0.026 s | 3 KBi |
#11 |
Correcto
|
0.022 s | 3 KBi |
#12 |
Correcto
|
0.061 s | 5 KBi |
#13 |
Correcto
|
0.061 s | 5 KBi |
#14 |
Correcto
|
0.055 s | 5 KBi |
#15 |
Correcto
|
0.038 s | 5 KBi |
#16 |
Correcto
|
0.048 s | 5 KBi |
#17 |
Correcto
|
0.032 s | 3 KBi |
#18 |
Correcto
|
0.025 s | 3 KBi |
#19 |
Correcto
|
0.016 s | 3 KBi |
#20 |
Correcto
|
0.025 s | 3 KBi |
#21 |
Correcto
|
0.347 s | 29 KBi |
#22 |
Correcto
|
0.384 s | 29 KBi |
#23 |
Correcto
|
0.38 s | 29 KBi |
#24 |
Correcto
|
0.246 s | 36 KBi |
#25 |
Correcto
|
0.396 s | 29 KBi |
def convert_to_disjoint_cycles(perm): used = {} for i in range(len(perm)): if i in used: continue cycle = [i] used[i] = (cycle, 0) while perm[i] not in used: used[perm[i]] = (cycle, len(cycle)) cycle.append(perm[i]) i = perm[i] return used def result(perm, k): cycles = convert_to_disjoint_cycles(perm) res = [None for _ in range(len(perm))] for i in range(len(perm)): cyc, idx = cycles[i] j = (idx + (k % len(cyc))) % len(cyc) res[cyc[j]] = str(i + 1) return res N, K = map(int, input().split(" ")) arr = [int(i) for i in input().split(" ")] print(" ".join(result(arr, K)))