Editorial for COCI '23 Contest 1 #3 AN2DL
Submitting an official solution before solving the problem yourself is a bannable offence.
Prepared by: Martina Licul
To solve the first subtask, you only needed to determine the largest number in the table of size .
To solve the second subtask, you could iterate through all subtables of size and find the largest number in each of them by looping through all the elements in that subtable. The overall complexity of this approach is .
To solve the third subtask, you break the problem into two phases: in the first phase, you determine the table you would get if you considered a frame of size , and in the second phase, you create a new table using a frame of size on the table created in the first phase. The result is the table you are looking for. Let's describe the process for each phase.
In the first phase, you can solve it row by row. The first number you would write in the -th row of the table is the largest number among the numbers . The second number you write is the largest number among the numbers . The set of numbers you consider for determining the first and second number differs only in the elements and ; all other elements are the same. Therefore, you can use a data structure like a multiset, where you can insert elements in and find the largest element in . You insert the first elements of the first row into the structure and write down the largest among them. Then, you remove from the structure and add . Write down the largest among them as the second number in the first row of the new table. By repeating this process to the end of the row, for each row, you get the table for the first phase.
In the second phase, you repeat a similar process for the columns using a similar data structure. This process results in the final table. The overall complexity of this approach is .
To solve the fourth subtask, you need to speed up the approach from the third subtask. Instead of inserting an element into a structure in , you want to do it in . You can use a data structure called a monotonic queue, which allows you to do this in . You can learn more about it on this link. The overall complexity of this approach is .
Comments