#P3693. Cirno's Ice House Simulation

    ID: 16944 Type: Default 1000ms 256MiB

Cirno's Ice House Simulation

Cirno's Ice House Simulation

Cirno has obtained an N×N square of snow field and plans to build an ice‐house using her ice blocks. However, she does not directly gather ice – instead she uses powerful ice barrages to freeze the snow. Each grid cell on the ground (height 0) has a freeze degree initially 0 (with maximum 4). When a cell is hit by an ice barrage, its freeze degree increases by 1 (unless it is already 4). Subsequently, whenever Cirno performs the MAKE_ICE_BLOCK operation, she collects an ice block from every cell whose freeze degree is exactly 4 and resets that cell’s freeze degree to 0. These ice blocks are later used in constructing the walls and roof of her planned ice‐house.

The house is planned as a rectangular cuboid with walls of thickness 1. The planned house occupies a region which includes its walls – its top‐left (northwest) corner is fixed at grid cell (HR, HC), its length (number of rows) is HX and its width (number of columns) is HY. A door of size 1×2 will be provided by leaving a gap at ground level in one of the walls (but not at a corner). Except for the final roof–making process, ice blocks will only be placed at heights in the range [0, HM–1]. Initially, Cirno has 0 ice blocks in her inventory.

The program you write must simulate the following types of operations:

1. ICE_BARRAGE R C D S

  • Cirno stands at grid cell (R, C) and fires an ice barrage in one of eight directions (numbered 0 to 7) with strength S. The eight directions are numbered as follows:
    • 0: up (R–1, C)
    • 1: up–left (R–1, C–1)
    • 2: left (R, C–1)
    • 3: down–left (R+1, C–1)
    • 4: down (R+1, C)
    • 5: down–right (R+1, C+1)
    • 6: right (R, C+1)
    • 7: up–right (R–1, C+1)
  • The barrage affects all cells on that straight line from Cirno’s position up to distance S (including the starting cell). For each affected cell, if its current freeze degree is less than 4 then it is increased by 1; however, if the cell’s freeze degree is 4 it is not increased further. Moreover, if the barrage hits a cell on the ground which already has an ice block (i.e. a block placed at height 0), then the barrage is blocked – it does not affect that cell or any cells beyond it in that direction.
  • After the operation, output a single line: CIRNO FREEZED k BLOCK(S) where k is the total number of cells whose freeze degree was successfully increased by 1.
  • Example:
    Before:
    00000
    00000
    00000
    000x0
    00000
    Operation: ICE_BARRAGE 1 1 5 4
    After:
    00000
    01000
    00100
    000x0
    00000
    Output: CIRNO FREEZED 2 BLOCK(S)

2. MAKE_ICE_BLOCK

  • Cirno visits all ground cells. For each cell whose freeze degree is 4, she collects one ice block (adds one to her inventory) and resets that cell’s freeze degree to 0.
  • Output a single line: CIRNO MADE x ICE BLOCK(S),NOW SHE HAS y ICE BLOCK(S), where x is the number of ice blocks made in this operation, and y is her new total.

3. PUT_ICE_BLOCK R C H

  • This operation attempts to place an ice block at cell (R, C) at height H.
  • Priority of conditions (check in order):
    1. If Cirno’s inventory is 0, output CIRNO HAS NO ICE_BLOCK.
    2. If the block would be floating in mid‐air (i.e. if H > 0 and there is no ice block immediately below at height H–1) or if the target position already has an ice block, output BAKA CIRNO,CAN'T PUT HERE and ignore the operation.
    3. If the position (R, C) is outside the planned house area (i.e. R < HR or R > HR+HX–1, or C < HC or C > HC+HY–1), output CIRNO MISSED THE PLACE. The block is still placed and inventory is decreased.
    4. If the block is placed inside the house interior (defined as HR+1 ≤ R ≤ HR+HX–2 and HC+1 ≤ C ≤ HC+HY–2), then output CIRNO PUT AN ICE_BLOCK INSIDE THE HOUSE. The block is placed and inventory is decreased.
    5. Otherwise, the block is correctly placed on the house wall. Output CIRNO SUCCESSFULLY PUT AN ICE_BLOCK,NOW SHE HAS x ICE_BLOCK(S) (with x being her remaining inventory after placement). Also, if the block is placed at ground level (H = 0), reset the cell’s freeze degree to 0.

4. REMOVE_ICE_BLOCK R C H

  • This operation attempts to remove the ice block at cell (R, C), height H.
  • Priority of conditions:
    1. If no ice block exists at the target position, output BAKA CIRNO,THERE IS NO ICE_BLOCK.
    2. If, after removal, some ice blocks become unsupported (i.e. are part of a floating connected component), then remove all such unsupported blocks (they fall and break – they do not enter the inventory) and output CIRNO REMOVED AN ICE_BLOCK,AND k BLOCK(S) ARE BROKEN, where k is the number of blocks that broke (in addition to the block that was removed normally, which does go back to the inventory).
    3. If removal does not cause any other block to become unsupported, simply remove the block, add one to the inventory, and output CIRNO REMOVED AN ICE_BLOCK.

5. MAKE_ROOF

  • This operation is executed only once and always last. It indicates that Cirno is ready to complete her house by building the roof and then performing various finishing steps:
    • Cirno will try to place enough ice blocks (up to HX×HY in number) at the appropriate height to form a roof. If her inventory is insufficient for the roof, output SORRY CIRNO,NOT ENOUGH ICE_BLOCK(S) TO MAKE ROOF and terminate the simulation.
    • If the house’s wall height is less than 2 or if the effective interior area is less than 2, output SORRY CIRNO,HOUSE IS TOO SMALL and terminate.
    • Then, she removes any extra (mis‐placed) ice blocks from inside and outside the house. 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 and K2 are the counts of extra blocks inside and outside, respectively.)
    • If, while removing extra blocks, the roof collapses, output SORRY CIRNO,HOUSE IS BROKEN WHEN REMOVING BLOCKS and terminate.
    • Next, she fixes any defects in the walls using as few ice blocks as possible. If her inventory is insufficient for the repairs, output SORRY CIRNO,NOT ENOUGH ICE_BLOCKS TO FIX THE WALL and terminate.
    • Finally, she evaluates her house by outputting several lines:
      • GOOD JOB CIRNO,SUCCESSFULLY BUILT THE HOUSE
      • If no proper door (a 1×2 gap at ground level) exists, output HOUSE HAS NO DOOR; otherwise, output DOOR IS OK.
      • Then, output either WALL NEED TO BE FIXED or WALL IS OK depending on the wall’s integrity.
      • Then, output either CORNER NEED TO BE FIXED or CORNER IS OK based on the state of the corner columns. (If repairable using available ice blocks, she will fix them.)
      • Next, output CIRNO FINALLY HAS k ICE_BLOCK(S) where k is the final count in her inventory.
      • If the house is perfectly built – with complete walls, no extra blocks, a proper door (centered on one of the walls), and corners built in advance – also output CIRNO IS PERFECT!

You are to simulate the entire process sequentially. Once any of the special conditions (marked with • in the full description) are triggered, process that condition and then terminate without processing further operations.


Input Format: The first line contains six space‐separated integers: N, HR, HC, HX, HY, HM. The following lines each contain one operation. It is guaranteed that all parameters are valid integers and that all operations appear in the correct order (with MAKE_ROOF being the final operation). There will be more than two test cases.

Output Format: For each operation, output the corresponding message as described.

inputFormat

The first line contains six integers: N H_R H_C H_X H_Y H_M.

Each subsequent line contains one operation in one of the following formats:

  • ICE_BARRAGE R C D S
  • MAKE_ICE_BLOCK
  • PUT_ICE_BLOCK R C H
  • REMOVE_ICE_BLOCK R C H
  • MAKE_ROOF

The input terminates after the MAKE_ROOF operation is processed.

outputFormat

Output the messages corresponding to each operation, one per line (or more if specified by an operation), exactly as described in the problem statement.

sample

5 1 1 3 3 5
ICE_BARRAGE 1 1 5 4
MAKE_ICE_BLOCK
PUT_ICE_BLOCK 0 1 0
REMOVE_ICE_BLOCK 0 1 0
MAKE_ROOF
CIRNO FREEZED 4 BLOCK(S)

CIRNO MADE 0 ICE BLOCK(S),NOW SHE HAS 0 ICE BLOCK(S) CIRNO HAS NO ICE_BLOCK BAKA CIRNO,THERE IS NO ICE_BLOCK SORRY CIRNO,NOT ENOUGH ICE_BLOCK(S) TO MAKE ROOF

</p>