A Swedish millionaire wants to build a monument for her family. The names of all of her known ancestors (and later, her future descendants) will be inscribed to the sides of the monument. The form of the monument will be a rectangular block with a × a bottom/top squares and height b. That is, the bottom and top of the block will be a × a squares, and each of the four sides of the monument is an a × b rectangle. The values of a and b should be such that the four sides have as much space as possible, in order to fit as many names as possible.
The monument will be cut from a very special p × q × r rectangular stone block that has been crystallised in a regular cubic form. That is, we may view the stone as being composed of 1 × 1 × 1 unit blocks (unit cubes). Also the final monument will be composed of such unit cubes. The raw stone may only be cut perpendicular to the x-, y- or z-axis, along the borders between unit cubes.
The raw stone contains pores, in the form of empty unit cubes. The monument is required to be of high quality and is thus not allowed to contain any pores (empty unit cubes). You are given a 3D-map of the raw stone. The map describes which unit cubes are normal and which empty. Your task is to find such values for the size parameters a and b of the monument that
입력 3 2 5 PNNNN PNNNN NPPNP PNNNP NNNNP PPNNP 출력 24
출처: boi 2009