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.

To simplify, consider p,q,rn.

Naive solution: test all O(n2) possibilities for choosing a and b, in all possible O(n3) locations. At least O(n5) time.

Basic dynamic programming: fill values d[x,y,z,k]= maximum height b for a rectangle with base length a=k and a corner at (x,y,z). Results in O(n4) time.

Proposed solution: precompute in O(n3) time and space for each (x,y,z) what is the side-length of maximal full square with e.g. lower-right corner at (x,y,z) (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 O(n3) time traversal over all (x,y,z). The final solution is taken as the best found among three traversals (and precomputations): one for each orientation.


Comments

There are no comments at the moment.