Gibonni
Time limit1sMemory limit1024 MB
Given up to six tiles with a notch in the top row, find the largest rectangle area that a subset of them can tile without gaps, with rotations allowed.
- Level
Medium6 of 10
- Topics
- Backtracking, Brute force, Matrix
- Solved
- No attempts yet
Problem
At a spectacular concert in Zagreb's so-called fake Arena, Gibonni had his fan Marin fascinated by the shapes shown on the screens behind the musician.
Inspired by those shapes, Marin decided to end his programming career and become a potter. He wants to be a potter who uses only tiles that resemble the shapes from Gibonni's concert.
He already has such tiles. The -th tile is described by four natural numbers , , , as follows:
- The tile is made of unit squares. is the number of columns and is the number of rows.
- is either 1 or 2 and gives the tile type. In a tile of type , the top row is missing the square in column . In a tile of type , the top row is missing every square except the one in column . All other rows are complete.
Tiles can be rotated left and right, so each tile has at most four different orientations.

Illustration of all possible orientations for the tile described by 1 3 4 3
Marin wants to arrange his tiles into a rectangle of the largest possible area. He does not have to use all the tiles, but there must be no gaps between them. Find the area of that rectangle.
Input
The first line contains a natural number (), the number of tiles.
Each of the next lines contains four natural numbers , , , (, , , , ), describing the -th tile.
Output
Print one line with the requested area.
Hint
Explanation of the first test case: The illustration shows the tiles in input order and one way to form a rectangle of area 35. One tile is not used.

Explanation of the second test case:

Explanation of the third test case: The tiles from the statement cannot be arranged into a rectangle without gaps.

