An interesting way to solve 739E

Revision en1, by krismaz, 2017-01-26 23:33:21

Hi everyone!

I've just solved 739E - Гоша выходит на охоту in an easy but interesting way. However, it's quite different from what's described in the editorial, and I couldn't find any accepted codes that use this approach. That's why I'm curious if anyone solved this problem like me, and if this is a well-known trick :)

First, there's an easy O(n3) DP solution to the problem: for each (i, x, y) compute the best score using x PokeBalls and y UltraBalls on i first Pokemon.

How to improve it? Let's randomly shuffle all Pokemon. If we looked at the first i of them, then we'd expect to use around PokeBalls, and UltraBalls there (a and b are the total amount of balls of each type), because the places where we used them in the optimal solution are now randomly distributed... even though positions where we use PokeBalls are not independent from positions where we use UltraBalls.

Now, using some random walk properties we can (I hope!) say, that it's really unlikely that we'll deviate from those expected values by more than . So we can just do the brutal DP, but constrain ourselves to x and y from a specific range of size . After that the solution is O(n2) and get's accepted: 24153740

All opinions are welcome. Thanks :)

Tags round 381, dp, random_shuffle

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English krismaz 2017-01-26 23:33:21 1356 Initial revision (published)