#P15830. [JOI Open 2015] Colored Tiles
[JOI Open 2015] Colored Tiles
Description
In the year of 2018, the International Olympiad in Informatics will be held in Japan. In order to celebrate it, the committee of IOI is planning to make an artwork of “slightly odd design”, and decorate the competition venue with it. The committee requested the JOI (Just Odd Inventions) Co. Ltd. to make a design of it. The designers of JOI proposed the following:
- The artwork will be made on the rectangular board with cells. We will pave the board with tiles. The tiles will not overlap with each other.
- The size of the tile () is either or . The color of the tile is .
- We may rotate a tile of , and may use it as a tile of .
Moreover, they proposed the kinds of tiles for the artwork. However, they did not propose how to pave tiles on the board, which is the most important part of the design. Because the designs proposed by JOI are always beautiful, the committee decided to obey the proposal of JOI for the kinds of the tiles. The committee has to think of the way to pave the tiles on the board. The committee decided to pave the tiles in order to maximize the beauty of the design.
The beauty of the design is calculated as follows:
- For an edge of the cells on the board shared by two tiles with color and color , the score of it is .
- The beauty of the design is the total sum of the scores of the edges of the cells on the board.
If two tiles of shares the edges of two cells, we count the scores of these two edges independently.
You are to calculate the way to pave the tiles on the board whose beauty is as large as possible.
Task
Given the size of the board, the size and the color of each tile, and the way to calculate the beauty of the design, determine the way to pave the tiles whose beauty is as large as possible.
Input Format
There are five subtasks. Each subtask corresponds to a public input data. The format of each input data file is as follows.
- The first line of input contains four space separated integers . This means the rectangular board consists of cells, there are kinds of colors of the tiles, and tiles are used in the design.
- The -th line () of the following lines contains two space separated integers . This means the size of the tile is , and the color of the tile is .
- The -th line () of the following lines contains space separated integers . This means, when two tiles with color and color share an edge, the score is .
Output Format
Submit an output data file for each input data file. The output data file consists of lines. The -th line () describes the way to put the tile on the board in the following format.
- When , the -th line should contain two space separated integers . This means the tile is put on the cell located in the -th row from above and the -th column from left.
- When , the -th line should contain four space separated integers . This means the tile is put on the board so that it covers the cell located in the -th row from above and the -th column from left, and the cell located in the -th row from above and the -th column from left.
3 2 3 4
1 1
2 2
1 3
2 1
2 7 5
7 4 3
5 3 1
2 2
1 1 1 2
3 2
3 1 2 1
Hint
Sample 1 Explanation
In this sample input, the size of the board of the design is , and 4 tiles are used. The color and the size of each tile is as follows:
| Number | Color | Size |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | 1 | |
There is a tile of size with color 1, a tile of size with color 2, a tile of size with color 3, and a tile of size with color 1.
We put the tiles as follows. The numbers in the figure indicate the numbers of the tiles.
:::align{center}
:::
The beauty of the design is calculated as follows. The beauty of the design is 26.
- Since the tile 2 with color 2 and the tile 4 with color 1 share an edge, we get the score 7.
- Since the tile 2 with color 2 and the tile 1 with color 1 share an edge, we get the score 7.
- Since the tile 4 with color 1 and the tile 1 with color 1 share an edge, we get the score 2.
- Since the tile 4 with color 1 and the tile 3 with color 3 share an edge, we get the score 5.
- Since the tile 1 with color 1 and the tile 3 with color 3 share an edge, we get the score 5.
Constraints
All input data satisfy the following conditions.
- .
- .
- .
- .
- ().
- ().
- .
- ().
- ().
Subtasks
For each subtask, the values of , , , are as in the following table. For the values of , , see Grading.
| Subtask | ||||||
|---|---|---|---|---|---|---|
| 1 | 7 | 24 | 3 | 168 | 124 000 | 130 000 |
| 2 | 50 | 80 | 1800 | 3 260 000 | 3 850 000 | |
| 3 | 100 | 7200 | 7 420 000 | 9 220 000 | ||
| 4 | 7000 | 7 150 000 | 9 000 000 | |||
| 5 | 5200 | 11 700 000 | 13 850 000 | |||
Grading
This is an output-only task. There are five subtasks, and each subtask consists of one input data file. Submit an output data file for each subtask. Your score of each subtask is calculated as follows.
- If the way to put the tiles on the board does not satisfy the condition of the output file, the score is zero.
- If the way to put the tiles on the board satisfies the conditions of the output file, the score is calculated using the values of , as follows. Let be the beauty of the design of the way to put the tiles.
- If , the score is zero.
- If , the score is $\left\lfloor 1 + 19 \times \left( \frac{B - X}{Y - X} \right)^2 \right\rfloor$. Here, is the largest integer less than or equal to .
- If , the score is 20.
京公网安备 11011102002149号