你可以浏览这个题解的中文版本。
I think this is a great approach. As a training contest, problem F is much easier than problem E, and is the one of the the only three problems with data in the contest. That is our MX (Dream Bear), an OI training institution in China.
When I see this kind of constraint, I tend to think of bitset, which leads to the following two ideas.
Approach 1: Consider bitsets of size that maintain which numbers appear in each row. So enumerate and update the answer to the pair if . The time complexity and space complexity are .
Approach 2: Consider bitsets of size that maintain on which lines each number has appeared. For all that satisfies the condition there must be for all . From this, think of enumerating and taking the complement of the union set of all , then for legitimate there is . Since the answer is required to be minimal, each row can be sorted by , and the optimal is . Time complexity , space complexity .
Approach 1 is certainly not promising, and is not even as good as the plain analog . But we also wanted to use bitset to solve this problem, so we considered optimizing approach two. Observe that this can be a waste of time and space if a number appears only once in all rows, i.e., . This example reminds us that it is better to calculate the contribution of directly for fewer occurrences, and consider maintaining directly in a vector instead of a bitset.
This can be done with time complexity and space complexity .