Personality Test
Time limit3sMemory limit1024 MB
Find a pair of students a < b who gave identical answers to at least k common questions, choosing the smallest b then the largest a, or report -1.
- Level
Medium6 of 10
- Topics
- Bit manipulation, String, Brute force
- Solved
- No attempts yet
Problem
There are students taking a personality test with questions. Students are numbered from 1 to , and questions are numbered from 1 to . For each question, a student either answers it with a single uppercase Latin letter (A to Z) or does not answer it. Let be the string of characters for student . Its -th character is an uppercase letter if the student answered question , or a period (.) if not.
Two students are similar if there is a set of at least questions such that both students answered every question in the set, and for each question in the set they gave the same answer. For example, with , , , = BBC, = ..C, and = .BC, students 1 and 3 are similar because they gave the same answers to questions 2 and 3. Students 2 and 3 are not similar because they share only one matching question (question 3).
You want to find a pair of integers with such that students and are similar, or determine that no such pair exists. If several pairs exist, pick the one with the smallest . If there is still a tie, pick the one with the largest .
Input
The first line contains three integers , , and (, , ). Each of the next lines contains a string of characters. The -th line contains the string .
Output
Output one line containing the integers and for a similar pair, as described in the problem. If no such pair exists, output the integer -1.