Pia Atelier: Alchemist of the Mystery Competition
Time limit3sMemory limit512 MB
Choose and order 3 of up to 10 candidate 4x4 materials, placing each rotated onto a 5x5 furnace, to maximize a weighted color-sum quality.
- Level
Medium6 of 10
- Topics
- Brute force, Simulation, Implementation, Backtracking
- Solved
- No attempts yet
Problem
The game Pia Atelier: Alchemist of the Mystery Competition tells the growth story of Pia, a poor alchemist. The competition is the central part. Pia earns a living only when alchemy produces high quality goods and wins prize money. The story is long and is omitted here. This task asks you to check the competition logic.
You place distinct materials in order into a grid furnace and build a bomb of the highest possible quality. The competition supplies at most candidate materials. You choose of them, fix an order, and place them into the furnace.
Each furnace cell holds a quality number and an element color. At the start every cell has quality and white color. Each material has shape, and cell of a material holds two values.
- Efficacy: an integer from to that is added to the quality of one furnace cell.
- Element: a color that can change the element of one furnace cell, one of red
R, blueB, greenG, yellowY, and whiteW.
A material never sticks out of the grid. Rotation in steps of degrees is allowed, and tilted placement is not allowed. When a material is placed, the furnace changes as follows.
-
A cell outside the material does not change.
-
A cell under the material changes as follows.
- Quality grows by the efficacy of the material. A negative sum becomes , and a sum above becomes .
- Color stays the same when the material element is white, and otherwise becomes the material element color.
The bomb is complete only after all materials are placed. Let , , , and be the quality sums over cells colored red, blue, green, and yellow in the finished furnace. The bomb quality is .
Given the candidate materials, choose and place them to maximize the bomb quality.
Input
The first line holds a natural number , the count of candidate materials ().
The next lines hold the materials in order. Each material uses lines. The first lines hold efficacy: integers separated by spaces on each line. The next lines hold elements: characters separated by spaces on each line. Each character is one of R, B, G, Y, W.
Output
Print the maximum bomb quality on the first line.
Hint
The placement proceeds as follows.
- Initial furnace.
- Place the second material with its top left corner at row , column , rotated once counterclockwise.
- Place the third material with its top left corner at row , column , without rotation.
- Place the first material with its top left corner at row , column , rotated once counterclockwise.
The sums are , , , and , so the final quality is .