Editorial for TLE '16 Contest 3 P5 - LAN Party


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: d

In this editorial, let N=max(R,C).

Subtask 1

It is sufficient to check every possible square after every removal, then print the answer. There are O(N2) corners to choose from, and O(N) possible square sizes. Each square takes O(N2) time to check. Therefore, a removal takes O(N5) time to process.

Time Complexity: O(MN5), which can be O(N7) in the worst case.

Subtask 2

It is possible to reduce the amount of checking required. For each of the M removals, generate a 2D sum array in O(N2) time. Each square now takes O(1) time to check. The best square size starts at 0, and it only matters when the best size gets beaten, so the O(N3) possible squares are now reduced to O(N2) possible squares. Therefore, a removal would take O(N2) 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 O(N2) and O(1) removals. However, this optimization is unlikely to solve the last subtask in time.

Time complexity: O(MN2), which can be O(N4) in the worst case.

Subtask 3

It is important to keep track of all O(N3) 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 X is true but needs to be removed, the four squares of size X+1 should be removed. Therefore, the total number of operations done is O(N3). It may be interesting that the first removal takes O(N3).

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 0.

Time complexity: O(N3)


Comments

There are no comments at the moment.