1523C.md (3625B)
1 Source: https://codeforces.com/problemset/problem/1523/C 2 3 C. Compression and Expansion 4 5 time limit per test 6 7 2 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  22 23 William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. 24 25 A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: 26 27 1. Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or 28 2. Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). 29 30 Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. 31 32 When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. 33 34 William wants you to help him restore a fitting original nested list. 35 36 Input 37 38 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. 39 40 The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. 41 42 Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. 43 44 It is guaranteed that in each test case at least one fitting list exists. 45 46 It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. 47 48 Output 49 50 For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. 51 52 If there are multiple answers, print any. 53 54 Example 55 56 Input 57 58 ``` 59 2 60 4 61 1 62 1 63 2 64 3 65 9 66 1 67 1 68 1 69 2 70 2 71 1 72 2 73 1 74 2 75 ``` 76 77 Output 78 79 ``` 80 1 81 1.1 82 1.2 83 1.3 84 1 85 1.1 86 1.1.1 87 1.1.2 88 1.2 89 1.2.1 90 2 91 2.1 92 2.2 93 ``` 94 95 Note 96 97 In the second example test case one example of a fitting list is: 98 99 1 100 101 1.1 102 103 1.1.1 104 105 1.1.2 106 107 1.2 108 109 1.2.1 110 111 2 112 113 2.1 114 115 2.2 116 117 This list can be produced by using the sequence of operations shown below:  118 119 1. Original list with a single item $1$. 120 2. Insert item $2$ by using the insertion operation of the second type after item $1$. 121 3. Insert item $1.1$ by using the insertion operation of the first type after item $1$. 122 4. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. 123 5. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. 124 6. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. 125 7. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. 126 8. Insert item $2.1$ by using the insertion operation of the first type after item $2$. 127 9. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.