DIFFDIAG - Differential Diagnosis
Daniel enjoys watching TV series. One of his favorite is "Doctor Chaos". In this series the medical genius is saving people by making difficult diagnosis. In his work he employs the differential diagnosis method. Doctor Chaos writes all the symptoms the patient have on the white board and his team tries to find out the disease which explains those symptoms best. Sometimes some symptoms are not caused by the disease itself. Sometimes some symptoms are not revealed yet and are not written on the board. Anyhow the team chooses come candidate-diseases and then runs the tests to identify the right one. Help Doctor Chaos by making a program which find out the diseases that are explaining the set of symptoms the best way. We'll say that the disease explains the set of symptoms the best way if it explains the most symptoms from the set among all known diseases.
Input
The first line of the input file contains number n - the amount of diseases known to Chaos and his team. Then n lines follow describing each disease. The description of the disease starts with the name of the disease. Then number k follows, that is the amount of different symptoms caused by the disease. Then there go the names of the symptoms separated by spaces. After the description of all the diseases there is number t - the amount of cases to diagnose. After that t lines follow each containing a set of symptoms. Each set starts with the number q - the amount of different symptoms. Then q names of the symptoms follow separated by spaces. The names of all diseases and symptoms consist of only small latin letters and don't exceed 20 characters. Each symptom in each set is explained by at least one disease.
Constraints
1 <= n <= 1000
1 <= k <= 10
1 <= t <= 10000
1 <= q <= 10
There are no more than 1000 different symptoms.
Output
For each case to diagnose first print the line "Diagnosis #x:" where x is the case number starting from one. Then list all the diseases which explains the corresponding set of symptoms best. The diseases should be listed one in line and in the same order in which they were given in the input file.
Example
Input: 3 migraine 2 headache nausea poisoning 3 nausea stomachache fever flu 3 fever cough headache 4 1 fever 2 nausea headache 2 nausea cough 4 fever nausea cough headache Output: Diagnosis #1: poisoning flu Diagnosis #2: migraine Diagnosis #3: migraine poisoning flu Diagnosis #4: flu
hide comments
saint_ying_xtf:
2023-06-28 05:23:18
why O(n*t*q*log2(n)) TLE? |
|
[Trichromatic] XilinX:
2009-11-04 17:31:21
I think my algorithm has same complexity as yours, but, the constant of your program and useful "break"s are important maybe. |
|
SALVO:
2009-11-04 16:19:34
Can any one tell me the time complexity needed to get AC ?
|
Added by: | Spooky |
Date: | 2009-11-03 |
Time limit: | 1.136s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 NODEJS OBJC PERL6 SQLITE VB.NET |
Resource: | Advancement Autumn 2009, http://sevolymp.uuuq.com/ |