#K63767. Tree Planting in a Grid

    ID: 31827 Type: Default 1000ms 256MiB

Tree Planting in a Grid

Tree Planting in a Grid

You are given a grid with R rows and C columns. Your task is to plant trees represented by the character T in the grid. The placement of trees must satisfy the following conditions:

  • No two trees are adjacent vertically, horizontally, or diagonally. Formally, for any tree placed at position \((i,j)\), none of its neighbors \((i+\delta_i, j+\delta_j)\) (with \(\delta_i,\delta_j \in \{-1,0,1\}\) except \(\delta_i = \delta_j = 0\)) should contain a tree.
  • In each row, the number of trees must not exceed a given limit L.

A valid strategy that meets these conditions is to place trees at positions in each row with even column indices (0-indexed) until the limit L is reached. You can assume that a solution always exists under the given constraints.

Constraints in LaTeX:

\[ \begin{aligned} &\text{For every row } i, \quad \sum_{j=0}^{C-1} [grid(i,j) = T] \le L,\\ &\text{For every tree at } (i,j), \quad grid(i+\delta_i, j+\delta_j) \neq T, \quad \forall\, \delta_i,\delta_j \in \{-1,0,1\} \text{ with } (\delta_i,\delta_j) \neq (0,0). \end{aligned} \]

inputFormat

The input consists of a single line containing three space-separated integers: R, C, and L, representing the number of rows, columns, and the maximum number of trees allowed per row respectively.

outputFormat

Output R lines, each being a string of length C that represents a row of the grid. In each row, a character T indicates a tree, and a period . indicates an empty cell.

## sample
4 4 2
T.T.

T.T. T.T. T.T.

</p>