1254A.md (3913B)
1 Source: https://codeforces.com/problemset/problem/1254/A 2 3 A. Feeding Chicken 4 5 time limit per test 6 7 1.5 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. 22 23 His farm is presented by a rectangle grid with $r$ rows and $c$ columns. Some of these cells contain rice, others are empty. $k$ chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm. 24 25 Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements: 26 27 * Each cell of the farm is assigned to exactly one chicken. 28 * Each chicken is assigned at least one cell. 29 * The set of cells assigned to every chicken forms a connected area. More precisely, if two cells $(x, y)$ and $(u, v)$ are assigned to the same chicken, this chicken is able to walk from $(x, y)$ to $(u, v)$ by passing only its cells and moving from each cell to another cell sharing a side. 30 31 Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him. 32 33 Input 34 35 Each test contains multiple test cases. The first line contains the number of test cases $T$ ($1 \le T \le 2 \cdot 10^4$). Description of the test cases follows. 36 37 The first line of each test case contains three integers $r$, $c$ and $k$ ($1 \leq r, c \leq 100, 1 \leq k \leq 62$), representing the size of Long's farm and the number of chickens Long has. 38 39 Each of the next $r$ lines contains $c$ characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm. 40 41 It is guaranteed that the sum of $r \cdot c$ over all test cases does not exceed $2 \cdot 10^4$. 42 43 Output 44 45 For each test case, print $r$ lines with $c$ characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens. 46 47 If there are multiple optimal answers, print any. 48 49 Example 50 51 Input 52 53 ``` 54 4 55 3 5 3 56 ..R.. 57 ...R. 58 ....R 59 6 4 6 60 R..R 61 R..R 62 RRRR 63 RRRR 64 R..R 65 R..R 66 5 5 4 67 RRR.. 68 R.R.. 69 RRR.. 70 R..R. 71 R...R 72 2 31 62 73 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR 74 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR 75 ``` 76 77 Output 78 79 ``` 80 11122 81 22223 82 33333 83 aacc 84 aBBc 85 aBBc 86 CbbA 87 CbbA 88 CCAA 89 11114 90 22244 91 32444 92 33344 93 33334 94 abcdefghijklmnopqrstuvwxyzABCDE 95 FGHIJKLMNOPQRSTUVWXYZ0123456789 96 ``` 97 98 Note 99 100 These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice. 101 102 In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is $0$. 103 104  105 106 In the second test case, there are $4$ chickens with $3$ cells of rice, and $2$ chickens with $2$ cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is $3 - 2 = 1$. 107 108  109 110 In the third test case, each chicken has $3$ cells with rice.  111 112 In the last test case, since there are $62$ chicken with exactly $62$ cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.