Editorial for COCI '17 Contest 1 #3 Lozinke


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.

We can solve this task in the following way: for each password X_i, we answer the query "How many other passwords exist that contain X_i as a substring?"

If, for each password, we solve the queries by iterating over all the passwords and checking each possible substring, we can solve the task for 40\% of total points. The complexity of this algorithm is \mathcal O(N^2 L^2), where N is the number of users, and L is the password length.

The solution can be sped up by calculating in advance, for each password, the different substrings it contains, and answer the queries by counting the number of times a substring appeared. The counting can be solved using a hash table, which is already implemented in most programming languages. The total complexity is \mathcal O(NL^2).


Comments

There are no comments at the moment.