Nikita and the Game

  • + 0 comments

    Editorial code is wrong, if you try this input:

    3
    8
    1 1 2 2 3 3 6 6
    8
    6 6 1 1 3 3 2 2
    8
    1 6 6 1 2 2 3 3
    

    All of sets are the same(items in different order), and you will get 3, 2, 0, output! The code doesn't check all possible partitions:

    (6, 6) or (3, 3, 2, 2, 1, 1) vs
    (6, 3, 3) or (6, 2, 2, 1, 1) vs
    (6, 3, 2, 1) or (6, 3, 2, 1) vs
    

    Also it failse in this case:

    1
    5
    3 4 5 6 8 
    

    It outputs 0, instead of 1, (3,4,6),(5,8) The problem seems to be NP-Hard, so I don't think there is any optimal solution.