Editorial for TLE '16 Contest 3 P5 - LAN Party
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
In this editorial, let .
Subtask 1
It is sufficient to check every possible square after every removal, then print the answer. There are corners to choose from, and possible square sizes. Each square takes time to check. Therefore, a removal takes time to process.
Time Complexity: , which can be in the worst case.
Subtask 2
It is possible to reduce the amount of checking required. For each of the removals, generate a 2D sum array in time. Each square now takes time to check. The best square size starts at , and it only matters when the best size gets beaten, so the possible squares are now reduced to possible squares. Therefore, a removal would take time to process.
There is a possible optimization which keeps the information of the best square so far. If a removal is not in the square, the answer will stay the same. This creates a mixture of and removals. However, this optimization is unlikely to solve the last subtask in time.
Time complexity: , which can be in the worst case.
Subtask 3
It is important to keep track of all squares in an array. Initially, all values in the array are set to true. When a person leaves, then all of the squares containing that person must be set to false. This can be accomplished with a DFS. Whenever a square of size is true but needs to be removed, the four squares of size should be removed. Therefore, the total number of operations done is . It may be interesting that the first removal takes .
To get the maximum square size available, one can use a histogram of available square sizes. The only corner case is when everyone leaves and the answer is now .
Time complexity:
Comments