Разбор
Problem Author: | Illia Shevchenko |
Prepared by: | Illia Shevchenko, Maksym Shvedchenko |
Editorial by: | Illia Fursov |
Group 1. .
In this group, the condition about the equality of the strings is already satisfied. But we also need the strings not to be all equal, thus we need to change any two strings so that they are equal, but not equal to the other two. You can change the same character in both strings, and it will take operations ( for both strings), so the answer for this group is always .
Time and memory complexity: (or ) (you can even not read any of the input)
Group 2. .
Note that when making string equal to you can avoid making them equal to the other strings. If there is some index such that , then you can make equal to if there is no other string such that and make equal to otherwise.
If , then the answer is as in the previous group. Otherwise, you can choose any of the first three strings — for example, — and make it equal to . Let's say that the distance between two strings of the same length is the number of positions where their characters are different. Then, the number of operations needed to make equal to is , and this is the answer for this group, because if we make equal to , then is not equal to anymore and the pairs of equal strings become different.
Time complexity: (because of function)
Memory complexity:
Group 3. .
Still, if , the answer is . Otherwise, there are two options to satisfy the conditions: make equal to in operations or make equal to and equal to in operations. But actually, , so the answer is .
Time complexity:
Memory complexity:
Group 4. .
In this group you can check all the pairs of pairs you can make to satisfy the conditions and take the minimum number of operations needed to do it out of these pairs. For every pair, this number is if and if .
To check all the cases, you can try to "connect" the string with ( and ), "connect" another two strings with each other, calculate the sum of needed number of operations for both pairs and take the minimum result out of all cases.
Time and memory complexity: .
Group 5.
The solution for this group is the same as for the previous one, but now you need to calculate the minimum sum of 's instead of just zeros and ones.
Time and memory complexity: .