Regarding problem TRPLSRT of codechef long challenge may 2020 div 2

Revision en1, by prthydv5, 2020-05-09 05:24:43

I tried to solve the problem TRPLSRT of codechef may 2020 long challenge div 2. I tried to solve it in 3 passes. In pass 1 i selected the triplets which after performing operation on all 3 will make all 3 go at their correct positions. Then i performed operations on such triplets. In pass 2 i selected the triplets which after performing operation on all 3 will make atleast 2 go at their correct positions. Before doing pass 3 i made a new array(ones[]) which would consist of indices of elements whose values are each other’s indices. Ex — a[1] = 6 and a[6] = 1. In this new array indices will be stored in increasing order for every pair of such numbers. So for above example their indices will be stored like 1, 6. In pass 3 I take every 3 consecutive indices from this new array and perform operation on the elements at these indices such that i1 is the third number, i2 is the second number and i3 is the first number of these 3 consecutive indices from left. I implemented it but I am getting WA. I don’t know if I have not correctly implemented this logic or there is a better logic which sorts in fewer number of operations. I have attached images of my code.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English prthydv5 2020-05-09 05:24:43 1242 Initial revision (published)