why is my approach wrong?

Revision en1, by dorasainath955, 2024-10-10 14:41:06

Submission
C1. Adjust The Presentation (Easy Version)

Approach: Assume that answer is "YA" and try to contradict it, if contradicted print "TIDAK"


  1. create a unique vector that consists of elements of "b" in such a way that no two consecutive elements are repeating
    b = {1, 1, 2, 2, 3} unqiue = {1, 2, 3}
  2. create a map mp that stores whether a element element has already occured(useful to verify if the slide encountered, bi can be given by person with same as bi).
    eg: b = {1, 2, 2, 1}, a = {1, 2, 3}, since person-1 and person-2 can give slide-1, 2. Then again we encountered slide-1 at b[3](zero index) so person-1(he's visited it) can be rearranged into giving slide-1 at b[3], map stores this information
    • Iterate through all elements of unique if the index i goes out of bounds for array a then break the loop;
    • if you find a[i] != b[i] && mp[unique[i]]==false then we can't arrange the persons in array to get our element bi print "TIDAK"
Tags constructive algorithms, greedy

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English dorasainath955 2024-10-10 14:41:06 1426 Initial revision (published)