Editorial for Baltic OI '09 P6 - Monument
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
To simplify, consider .
Naive solution: test all possibilities for choosing
and
, in all possible
locations. At least
time.
Basic dynamic programming: fill values maximum height
for a rectangle with base length
and a corner at
. Results in
time.
Proposed solution: precompute in time and space for each
what is the side-length of maximal full square with e.g. lower-right corner at
(this is computed along one of the three orientations: xy-plane, xz-plane and yz-plane). Then the solutions for the current orientation can be computed with an
time traversal over all
. The final solution is taken as the best found among three traversals (and precomputations): one for each orientation.
Comments