haleyk100198's blog

By haleyk100198, history, 8 years ago, In English

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.

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by haleyk100198 (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it -8 Vote: I do not like it

For P = 2, Hope this AC code and this helps you. The code is not mine, but I found my explanation to be equivalent to the implementation.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Does anyone have a code for large case P = 3? Thanks!