Under construction

Still being built. Things may change

Sprinkler Layout

Time limit1sMemory limit128 MB

Summary
Tile every empty cell with 3-cell sprinklers in the prescribed row-major order, then drill fence holes and assign letters a to z greedily.
Level

Medium5 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

Sara farms a large rectangular piece of land. The land is a grid of 5R5R rows and 5C5C columns. A horizontal fence crosses the land after every fifth row and a vertical fence crosses it after every fifth column, so the fences cut the land into R×CR \times C areas of 5×55 \times 5 cells called fields.

Birds eat the crops, so some fields have a scarecrow. A scarecrow takes one cell, and a field holds at most one scarecrow.

During a drought Sara waters the crops with sprinklers. A sprinkler has one main nozzle and two side nozzles. The main nozzle takes one cell, and the two side nozzles take two different cells that touch the main nozzle from above, from below, from the left, or from the right. A sprinkler therefore takes three cells and waters all three of them.

Sara wants exactly one nozzle on every cell that has no scarecrow. A cell with a scarecrow takes no nozzle, and no nozzle may lie outside the land.

The three cells that one sprinkler waters need not lie in the same field. When they reach into a neighboring field, Sara drills a hole in the fence between the two cells.

Given the land, print an arrangement of sprinklers.

Input

The first line contains two integers RR and CC (1≤R,C≤1001 \le R, C \le 100), the size of the land.

Then 6R−16R-1 lines follow, each with 6C−16C-1 characters. They describe the land and the fences between the fields. The fence is infinitely thin, but it still takes one character in the picture.

One cell is one character. An empty cell is . and a cell with a scarecrow is #. A vertical fence is |, a horizontal fence is -, and a crossing of two fences is +.

A field holds at most one scarecrow. The data is such that the procedure described in the output section runs to the end.

Output

Print 6R−16R-1 lines of 6C−16C-1 characters, showing the land with the sprinklers in the same format as the input. Keep # on every cell with a scarecrow, replace every empty cell with a lowercase letter from a to z, and replace the fence character with _ at every hole. The arrangement satisfies these four rules.

  1. The three cells that one sprinkler waters carry the same letter, even when they do not all lie in the same field.
  2. When two cells that touch inside one field are watered by different sprinklers, they carry different letters.
  3. When two cells that touch across a fence are watered by different sprinklers and the fence between them has a hole, they carry different letters.
  4. Two cells that touch across a fence may carry the same letter as long as the rules above hold.

Several arrangements can satisfy the rules, so print the one that this procedure builds. Rows are counted from the top and columns from the left.

Read the cells from top to bottom, and from left to right inside a row. When you reach a cell (r,c)(r, c) that has no scarecrow and that no sprinkler waters yet, put a sprinkler on it. Use the first shape in this list whose three cells all lie inside the land, hold no scarecrow, and take no water yet.

  1. (r,c)(r, c), (r,c+1)(r, c+1), (r,c+2)(r, c+2)
  2. (r,c)(r, c), (r,c+1)(r, c+1), (r+1,c)(r+1, c)
  3. (r,c)(r, c), (r,c+1)(r, c+1), (r+1,c+1)(r+1, c+1)
  4. (r,c)(r, c), (r+1,c)(r+1, c), (r+1,c+1)(r+1, c+1)
  5. (r,c)(r, c), (r+1,c−1)(r+1, c-1), (r+1,c)(r+1, c)
  6. (r,c)(r, c), (r+1,c)(r+1, c), (r+2,c)(r+2, c)

Drill a hole in every fence character that separates two cells watered by the same sprinkler, and leave every other fence character as it is. A + is never a hole.

Number the sprinklers in the order you place them. Going in that order, give each sprinkler the first letter from a to z that keeps rules 2 and 3 against the sprinklers that already carry a letter.

Examples6

  1. Example 1

    Input
    2 2
    .....|.....
    .....|.....
    ...#.|.....
    .....|.....
    .....|.....
    -----+-----
    .....|.....
    .....|.....
    .....|.....
    .....|.....
    .....|.....
    
    Expected output
    aaabb_baaab
    bbbaa_accbb
    aaa#b_bcaaa
    bbbab|dddbb
    cccaa|aaaba
    -----+----_
    aaabb_bccaa
    bbbaa_acbbb
    aaabb_baaac
    bbbaa_abbcc
    aaacc_cbaaa
    
  2. Example 2

    Input
    1 1
    .....
    .....
    ..#..
    .....
    .....
    
    Expected output
    aaabb
    cccba
    aa#aa
    abbbc
    dddcc
    
  3. Example 3

    Input
    1 3
    .....|.....|.....
    .....|.....|.....
    .....|.....|.....
    .....|.....|.....
    .....|.....|.....
    
    Expected output
    aaabb_baaab_bbaaa
    bbbaa_abbba_aabbb
    aaabb_baaab_bbaaa
    bbbaa_abbba_aabbb
    aaabb_baaab_bbaaa
    
  4. Example 4

    Input
    3 1
    .....
    .....
    .....
    .....
    .....
    -----
    .....
    .....
    .....
    .....
    .....
    -----
    .....
    .....
    .....
    .....
    .....
    
    Expected output
    aaabb
    cccba
    bbbaa
    aaabb
    cccba
    ----_
    bbbaa
    aaabb
    cccba
    bbbaa
    aaabb
    ---_-
    aaaba
    bbbaa
    aaabb
    cccba
    bbbaa
    
  5. Example 5

    Input
    1 2
    ....#|#....
    .....|.....
    .....|.....
    .....|.....
    .....|.....
    
    Expected output
    aaab#|#aaab
    cccbb|cccbb
    aaadd_daaac
    bbbaa_abbcc
    aaacc_cbaaa
    
  6. Example 6

    Input
    2 1
    .....
    .....
    .....
    .....
    ..#..
    -----
    ..#..
    .....
    .....
    .....
    .....
    
    Expected output
    aaabb
    cccba
    bbbaa
    aaabb
    bb#ba
    _---_
    ba#aa
    caabb
    ccdba
    aadda
    abbba