#P3693. 琪露诺的冰雪小屋
琪露诺的冰雪小屋
Description
Cirno happens to get a square snowy field of size , and she wants to build an ice house on it.
But the mischievous ⑨ won’t seriously collect ice blocks; instead, she will use ice barrages on this land to make ice blocks and then stack them one by one to build a house.
Cirno makes ice blocks as follows: she stands on some cell, then fires a powerful ice barrage in one of the eight directions: up, down, left, right, up-left, down-left, up-right, down-right. The barrage affects all cells along that straight line within a certain distance.
Each ground cell has a freezing level, initially . When a cell is affected once by an ice barrage, its freezing level increases by , capped at .
Between shots, Cirno visits all cells whose freezing level is , gathers the snow there to make one ice block (size ), and resets their freezing levels to .
Cirno will use these ice blocks to build the house. She has already planned the house’s length, width, and placement at the start, but she is unwilling to decide the house’s height in advance.
Cirno’s plan: the house should look like a rectangular cuboid.
She will first build the four walls (thickness cell), and near the ground (of course) leave a -wide and -high opening as a door. (Obviously, the door cannot be at a wall corner, but it can be adjacent to a corner.)
Whenever she likes, she will stop building the walls and put a -thick roof over the top in one go, making the house a hollow, roofed cuboid.
The plan is well prepared, yet Cirno still wants your help to write a program to remind her not to mess up. The required features of this program are described below.
The field consists of rows and columns, cells in total. (Indexing starts from , i.e., row and column exist, while row and column do not.) Each cell has a freezing level in , initially . Note that space is three-dimensional, while the freezing level is an attribute of the ground.
Cirno wants to place the top-left corner of the house at row , column (the outer wall is part of the house, so the top-left corner is not inside the house; it is on the outer wall and is the corner of the wall).
The house’s length (parallel to columns) is , and its width (parallel to rows) is , including the walls. It is guaranteed that the house stays within the field.
Except for placing the final roof, Cirno will only place ice blocks at heights in .
Initially, Cirno has no ice blocks. In the following illustrations, we use a top-down view:
0000
0000
4x90
0x01
Numbers represent the current freezing level of a ground cell. If an ice block is placed at ground level (height ), we mark it by the letter x.
If there is no ice block at ground level, but there is an ice block somewhere directly above that position, we still use a number to indicate the ground freezing level, but add to it. That is, if you see a number , it means the ground is empty, but there is an ice block above, and the ground freezing level is .
First operation: ICE_BARRAGE R C D S
Cirno stands at row , column , and fires a barrage of strength toward direction .
$R, C, D, S \in \Z, 0 \le D \le 7, 0 \le R, C, S < N$.
Direction indices: means up , means up-left ,
means left , means down-left ,
means down , means down-right ,
means right , means up-right .
A barrage of strength increases by the freezing level of every cell “on the shooting line in that direction, within distance at most from Cirno (including the cell she stands on).” Special cases:
- If a cell’s freezing level is , it does not change.
- If the barrage path encounters an ice block placed on the ground (height ) at some position (i.e., the barrage hits a partially built house), the barrage is blocked and cannot affect that cell or any cells behind it.
- Any portion of the barrage outside the field is ignored.
For this operation, output one line: CIRNO FREEZED k BLOCK(S)
If this barrage successfully increases a cell’s freezing level by , we say the barrage has frozen that cell.
k is the total number of cells frozen by this barrage.
Example: Before firing, the map is:
00000
00000
00000
000x0
00000
After executing ICE_BARRAGE 1 1 5 4, the map becomes:
00000
01000
00100
000x0
00000
Output: CIRNO FREEZED 2 BLOCK(S)
Explanation: Cirno stands at row , column , fires a barrage of strength toward down-right, but it is blocked by x and only affects cells before x.
Second operation: MAKE_ICE_BLOCK
Cirno traverses all cells with freezing level , gathers one ice block from each, and resets their freezing levels to .
For this operation, output one line: CIRNO MADE x ICE BLOCK(S),NOW SHE HAS y ICE BLOCK(S)
This means Cirno made x ice blocks and now has y ice blocks.
For example, Cirno initially has ice blocks, and the map is:
0xxx
0x4x
0x9x
0400
After executing MAKE_ICE_BLOCK, it becomes:
0xxx
0x0x
0x5x
0000
Output: CIRNO MADE 3 ICE BLOCK(S),NOW SHE HAS 3 ICE BLOCK(S)
In this example, part of the house is already built, x denotes walls, and the 9 indicates that the ground at that position is empty but there is an ice block above (you can guess it’s the door). The only empty cell inside the room, the door position, and one position outside the room have freezing level , so ice blocks can be collected. After collecting, these three cells are reset to .
Third operation: PUT_ICE_BLOCK R C H
Place an ice block at row , column , height . .
Ground level is height . If placement succeeds, Cirno’s stock decreases by .
If the block is placed at ground level, the cell’s freezing level is immediately reset to .
There are several cases; smaller indices have higher priority, and exactly one case applies.
Only if case 1 is not satisfied can case 2 be considered, and so on.
- Cirno currently has no ice blocks and cannot place one. Output: CIRNO HAS NO ICE_BLOCK
- The ice block would be floating in the air, not attached to any other ice block, or the target position is already occupied.
In this case, output one line: BAKA CIRNO,CAN'T PUT HERE, and ignore this operation entirely. - The ice block is placed outside the planned house area, i.e.,
or
or or . Output one line: CIRNO MISSED THE PLACE
Even though Cirno misplaced the block, you cannot stop her from placing it. - The ice block is placed inside the house, occupying a space that should be kept empty, i.e.,
and
Before the roof height is finalized, we consider all positions satisfying the above as inside the house.
Output one line: CIRNO PUT AN ICE_BLOCK INSIDE THE HOUSE
Even though Cirno misplaced the block, you cannot stop her from placing it. - The ice block is placed at a correct position (ignore whether it blocks the reserved door space).
Output one line: CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS x ICE_BLOCK(S)
x is the remaining number of ice blocks after placing this one.
Fourth operation: REMOVE_ICE_BLOCK R C H
Remove the ice block at row , column , height .
There are several cases; smaller indices have higher priority, and exactly one case applies.
Only if case 1 is not satisfied can case 2 be considered, and so on.
- There is no ice block at the target position. Output: BAKA CIRNO,THERE IS NO ICE_BLOCK
- There is an ice block at the target position, and after removing it, at least one connected component of ice blocks becomes floating.
As in the following “side view,” x denotes an ice block and 0 denotes empty:
xxxx
x000
x000
x000
After removing the top-left ice block, the three blocks to its right in the top row lose support and form a floating connected component, which belongs to this case.
This ice block is successfully removed, Cirno’s stock increases by , and all floating connected components fall and shatter, disappearing completely
(neither added to the stock nor leaving any trace on the ground).
Output: CIRNO REMOVED AN ICE_BLOCK,AND k BLOCK(S) ARE BROKEN, where k is the number of shattered blocks.
3. Cirno removes the ice block and no other block is affected.
Cirno’s stock increases by . Output: CIRNO REMOVED AN ICE_BLOCK
Fifth operation: MAKE_ROOF
This operation appears exactly once and only as the last operation.
It indicates that Cirno has finished the four walls and only the roof remains!
In the general case, Cirno places the final ice blocks at the layer one unit above the highest height of the walls to form a roof. Then she removes all excessive blocks and repairs any defects in the walls.
You must execute the entire process in order. As soon as one of the special cases marked with • occurs, finish that special case and then terminate the process.
Everything described between special cases is the general case, and is assumed to occur unless a special case has already caused an early exit.
First, Cirno will place at most ice blocks at once to build the roof.
Why “at most”? Note that if previously misplaced blocks inside the house happen to serve as part of the roof, then no additional block is needed at those positions. Also, any blocks above the roof will later be treated as misplaced outside the house.
Note: while placing the roof, the plane at height might be touched.
Two special cases may occur before or after building the roof:
- Cirno does not have enough ice blocks to build the roof. Output: SORRY CIRNO,NOT ENOUGH ICE_BLOCK(S) TO MAKE ROOF
- The highest wall height is less than cells, or the interior usable space is less than two cells.
The ring occupied by the walls is not counted as interior space. When computing interior usable space, ignore misplaced blocks because they will be removed later.
Output: SORRY CIRNO,HOUSE IS TOO SMALL
(Special cases end.)
After this, assume Cirno has built the roof. Next, remove all excessive blocks. During removal, Cirno will try to minimize the number of blocks that shatter. If some wall block would shatter as a consequence of removing excessive blocks, she will first take down that wall block and then restore it when repairing the wall (clearly, this does not change whether the wall has defects, but it saves a block). She will not deliberately remove a wall block that would not shatter.
Output two lines:
K1 ICE_BLOCK(S) INSIDE THE HOUSE NEED TO BE REMOVED
K2 ICE_BLOCK(S) OUTSIDE THE HOUSE NEED TO BE REMOVED
K1 is the number of misplaced blocks inside the house; K2 is the number outside the house.
One special case may occur:
- Cirno removes all excessive blocks, but the roof collapses during removal.
Output: SORRY CIRNO,HOUSE IS BROKEN WHEN REMOVING BLOCKS
(Special cases end.)
After this, assume all excessive blocks have been removed. Next, repair any defects in the walls.
Definition of having wall defects: excluding the -wide and -high door, if from inside the house you can still see the outside through other openings, then the wall has defects.
If an empty spot is intended to be part of the door, it is not a defect. The house can have only one door.
If the walls have no defects, do not repair; otherwise, repair. You must record whether the walls had defects; this will be used later.
Repair strategy: use as few blocks as possible, at correct positions, to make the house no longer meet the definition of having wall defects (i.e., do not place extra blocks just to block line of sight). Under this definition, in most cases we can ignore the completeness of the four corner pillars because they are not visible from inside the room.
One special case may occur:
- Cirno does not have enough ice blocks to fix the wall defects.
Output: SORRY CIRNO,NOT ENOUGH ICE_BLOCKS TO FIX THE WALL
(Special cases end.)
After this, assume the house has been successfully built. You must output several lines to evaluate the house.
First, celebrate the completion: GOOD JOB CIRNO,SUCCESSFULLY BUILT THE HOUSE
- If at ground level no -wide and -high opening can be reserved for the door,
output: HOUSE HAS NO DOOR, and then Cirno will try to utilize wall defects to open a door.
Otherwise, output: DOOR IS OK - Next, output one line describing the wall’s completeness before repairs:
2.1. If the earlier record says the wall was incomplete and needed repairs, output: WALL NEED TO BE FIXED
2.2. If the earlier record says the wall was complete and needed no repairs, output: WALL IS OK - Next, one line about the completeness of the four corners.
If any of the four corner pillars is incomplete, output: CORNER NEED TO BE FIXED
In this case, if Cirno has enough blocks to fix the corner gaps, she will fix them immediately.
If not, she will collect just enough additional blocks and then fix the gaps.
Otherwise, output: CORNER IS OK
Finally, output: CIRNO FINALLY HAS k ICE_BLOCK(S)
k is the number of ice blocks Cirno has in the end.
Lastly, if the earlier record shows the walls were flawless with no positions to repair, there were no extra blocks either inside or outside the house with no positions to remove, no “house has no door” situation occurred, the four corners were fully built before making the roof (not completed via later repairs), and the door is exactly at the center of some wall (if even length, either of the two middle positions counts), then output:
CIRNO IS PERFECT!
Input Format
The first line contains a positive integer , the size of the field.
The second line contains a positive integer , the maximum height at which Cirno may place blocks.
The third line contains four positive integers , the row and column of the top-left corner of the house, and the house’s length and width.
The fourth line contains a positive integer , the number of operations.
The next lines each contain one operation; see the Description for formats.
Output Format
As described in the problem statement.
8
10
4 0 4 4
63
ICE_BARRAGE 2 1 1 3
ICE_BARRAGE 0 1 3 1
MAKE_ICE_BLOCK
PUT_ICE_BLOCK 3 2 0
ICE_BARRAGE 1 0 6 7
ICE_BARRAGE 2 0 6 7
ICE_BARRAGE 3 0 6 7
ICE_BARRAGE 4 0 6 7
ICE_BARRAGE 1 0 6 7
ICE_BARRAGE 1 0 6 7
ICE_BARRAGE 1 0 6 7
ICE_BARRAGE 1 0 6 7
MAKE_ICE_BLOCK
PUT_ICE_BLOCK 4 0 1
PUT_ICE_BLOCK 4 0 0
PUT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CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 7 BLOCK(S)
CIRNO FREEZED 7 BLOCK(S)
CIRNO FREEZED 0 BLOCK(S)
CIRNO MADE 8 ICE BLOCK(S),NOW SHE HAS 8 ICE BLOCK(S)
BAKA CIRNO,CAN'T PUT HERE
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 7 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 6 ICE_BLOCK(S)
CIRNO MISSED THE PLACE
CIRNO REMOVED AN ICE_BLOCK,AND 1 BLOCK(S) ARE BROKEN
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 5 ICE_BLOCK(S)
CIRNO PUT AN ICE_BLOCK INSIDE THE HOUSE
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 3 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 2 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 1 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 0 ICE_BLOCK(S)
CIRNO FREEZED 6 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 7 BLOCK(S)
CIRNO MADE 8 ICE BLOCK(S),NOW SHE HAS 8 ICE BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO MADE 8 ICE BLOCK(S),NOW SHE HAS 16 ICE BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO MADE 8 ICE BLOCK(S),NOW SHE HAS 24 ICE BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO FREEZED 8 BLOCK(S)
CIRNO MADE 8 ICE BLOCK(S),NOW SHE HAS 32 ICE BLOCK(S)
CIRNO REMOVED AN ICE_BLOCK
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 32 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 31 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 30 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 29 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 28 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 27 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 26 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 25 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 24 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 23 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 22 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 21 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 20 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 19 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 18 ICE_BLOCK(S)
CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS 17 ICE_BLOCK(S)
0 ICE_BLOCK(S) INSIDE THE HOUSE NEED TO BE REMOVED
0 ICE_BLOCK(S) OUTSIDE THE HOUSE NEED TO BE REMOVED
GOOD JOB CIRNO,SUCCESSFULLY BUILT THE HOUSE
DOOR IS OK
WALL IS OK
CORNER IS OK
CIRNO FINALLY HAS 1 ICE_BLOCK(S)
CIRNO IS PERFECT!
Hint
There are Subtasks. Each Subtask’s testdata satisfies certain conditions and also satisfies those of all Subtasks with larger indices.
For example, Subtask #0 also satisfies the conditions of Subtasks #0–5.
Each Subtask’s score is the minimum across all its test points.
Subtask #0 20%
Cirno only wants to play with ice barrages. She will not place any ice blocks and will not build the house (i.e., only operations 1 and 2).
Subtask #1 10%
Cirno will not remove already placed ice blocks.
Subtask #2 20%
Cirno is confident; she will build her igloo without MAKE_ROOF (in this case, the placement heights are still less than , and there is no MAKE_ROOF operation).
Subtask #3 20%
Cirno will be cautious when removing blocks and will not cause any ice blocks to fall. During MAKE_ROOF, removing excessive blocks will not cause the roof to collapse.
Subtask #4 20%
Cirno dislikes placing the door next to a corner pillar (the testdata guarantees that among all possible wall openings for the door, there exists an option where the door is not adjacent to a corner pillar).
Subtask #5 10%
, , , and all empty ground cells outside the house area form at most one connected component.
Note: When judging whether the wall has defects, if a candidate door opening is blocked by a block at that time, it is still considered blocked. “Can see the defect” is judged based on the state at that moment.
Translated by ChatGPT 5
京公网安备 11011102002149号