Google APAC Test 2017 Round E Problem D

Revision en2, by haleyk100198, 2016-11-06 11:32:59

I wonder if anyone here managed to solve Problem D Small in the recent Google APAC Test. I implemented my approach yet it somehow failed to cope with the small test case.

Link to problem: https://code.google.com/codejam/contest/5264487/dashboard#s=p3

My approach:

  1. Assume P=0, solve the problem for no swapping by keeping the minimum and maximum value of first n values. Divide the array into non-overlapping segments.

  2. Iterate through each segment, check the leftmost and rightmost position that could be used for dividing the segment into two. Say the segment [seg] = [a] + [b], check for all [a] and [b] where min(a[]) > max(b[]).

  3. Check for positions between the leftmost and rightmost. Say [seg] = [a] + [mid] + [b], solve [mid] for [P] = 0 for P = 0.

  4. Find the best segment to be used for further dividing for swapping. This should be the answer... Except it isn't according to judge. =[

Link to my code: http://pastebin.com/Sa5m7hVE

Any help is appreciated. =]

The problem D Large seems interesting with P = 3, and only two contestants solved it during the contest.

Tags apac test 2017, ggcj, round e

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English haleyk100198 2016-11-06 11:32:59 5 Tiny change: 'contestant solved it during contest.' -> 'contestants solved it during the contest.'
en1 English haleyk100198 2016-11-06 11:32:35 1239 Initial revision (published)