Editorial for COCI '10 Contest 3 #4 Znanstvenik
Submitting an official solution before solving the problem yourself is a bannable offence.
It is important to notice that if it is possible to delete rows from the top of the matrix leaving no two equal columns, the condition will also be satisfied if only rows are deleted. Hence the maximum can be found using binary search.
Now we need an efficient method to check, for a given , whether it is possible to delete the first rows leaving no two equal columns. If we read the columns as strings from the bottom up, a good idea is to sort them lexicographically. That way, any two equal columns will be next to each other, so we only need to check adjacent columns for equality up to length .
The described solution can be implemented with complexity , where .
An alternative solution could use hashing of individual columns, reducing column comparison to simple integer comparison (reducing complexity in the process). The details of this solution are left as an exercise for the reader.
Comments