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.
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 , we answer the query "How many other passwords exist that contain 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 of total points. The complexity of this algorithm is , where is the number of users, and 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 .
Comments