Wildcard MatchingProblem code: L2 |
All submissions for this problem are available.
Problem Statement Updated.
Johnny is the author of the famous open source software ByteDict (Bytelandian electronic dictionary).
Being a fan of the word game Scrabble, Johnny would like to make ByteDict useful for Scrabble training. Therefore, he has decided to implement the "Wildcard Matching" feature.
Wildcard matching allows ByteDict's users to search for words matching a given wildcard pattern. A wildcard pattern may include the characters '*' or '?' in addition to the characters of the alphabet. A '*' matches any sequence of characters (including the empty sequence) and a '?' matches any single character.
To be more precise, a wildcard pattern is matched with a word if we can replace each '?' with an alphabet character and each '*' with a sequence of alphabet characters so that after replacement, the pattern becomes identical to the word.
Now, as usual, please help Johnny implement the feature!
Input
The first line contains a number t (about 2) which is the number of test cases. Then t test cases follow. Each test case has the following form.
The first line contains two integers N and Q (1 <= N <= 55000, 1 <= Q <= 300) which are the number of words in the dictionary and the number of wildcard queries.
Each line in the next N lines contains a word from the dictionary. The alphabet consists of lower and uppercase characters as well as digits.
Each line in the next Q lines contains a wildcard pattern.
The length of each word does not exceed 25 and the length of each wildcard pattern does not exceed 5.
Each test case is separated by a blank line.
Output
For each wildcard query print a line containing the query itself and the number of words in the dictionary that match the query.
Print a blank line after each test case's output.
Example
Input: 2 1 7 abc abc cba a?? ??a *?a *** **a 7 4 spoj codechef uva tju onlinejudge Acmicpc Worldcup2010 *a* sp?* *c* uvc Output: abc 1 cba 0 a?? 1 ??a 0 *?a 0 *** 1 **a 0 *a* 1 sp?* 1 *c* 3 uvc 0
Comments

Fetching successful submissions

The less than symbols are
The less than symbols are broken. Again.
It also says that the length of the wildcard pattern does not exceed 5, yet the test cases show otherwise. Please fix.
Can this please be fixed?
Can this please be fixed?
As Stephen indicated, '*c*'
As Stephen indicated, '*c*' does not match 'Worldcup2010' if '*' matches only up to 5 chars, therefore '*c*' should show '2' matches only.
Uh, no, it doesn't say
Uh, no, it doesn't say anything about how many characters * can match. Just that the length of the wildcard string is at most 5, whereas *?*?*?*? is of length 8.
The problem statement has
The problem statement has been updated.
Argh... There seems to
Argh... There seems to something fishy with the judge's output/checker. I've verified my program with large testcases locally, with grep, and it gives correct output. But the judge refuses to accept ;-) And no one else has been able to get an AC on this one either.
To restate the obvious: (1) the matching (of non-wildcards) should be case-sensitive (2) * matches any number (including 0 or greater than 5) characters (3) Both * and ? match any character from the sets [A-Z], [a-z], [0-9].
if the input is 1 1
if the input is
1
1 1
abaca
*ac*
what will be the output
*ac* 1
or
*ac* 0
@Giri: In your example, do
@Giri: In your example, do you have a line of reasoning that explains the output being 0? I would say it should be 1 (but then my solution isn't AC'ed).
ohh... :hangs head in
ohh... :hangs head in shame:
Thanks, Stephen.
@Giri ... it should be 1 ...
@Giri ... it should be 1 ...
Judge data seems faulty or
Judge data seems faulty or not conforming to the standards. I sent a checker and it got a runtime error. Admins please confirm
Ok, only the test-cases are
Ok, only the test-cases are more than 2 i think. Otherwise everything seems fine :)
Sorry :)
Yup, it doesn't say there
Yup, it doesn't say there will be exactly 2 test cases.
I agree with the earlier
I agree with the earlier comments, the judge appears to be faulty here.
Checking.
Checking.
Judge appears to have been
Judge appears to have been fixed.
Can a wildcard pattern have
Can a wildcard pattern have length of 0 ?
A wildcard pattern cannot
Admin, I have solved three
Admin,
I have solved three problems. I am unable to view my name in Indian rankings. Please check.My country is showing as 11.I would be happy to see my name in the rankings.
Yeah, we are looking into
Yeah, we are looking into this. This should get solved tomorrow.
thanks a lot!
thanks a lot!
can any1 give me a worst case
can any1 give me a worst case input?
i thought
vvvvvvvvvvvvvvvvvvvvvvvvv repeated 55000 times and v*v*v repeated 300 times would be the worst case
Nobody will give you hints,
Nobody will give you hints, no.
I think
I think vvvvvvvvvvvvvvvvvvvvvvvvv is 25 characters long
so it will take 55000X300X25 units of time at min.
for more than 2 test cases it will take more than 2 secs?
Isn't the time limit less than what shud be?
eg:
int a=55000,b=300,i,j,c;
for(int test=0;test<3;test++)
for(i=0;i<b;i++)
for(j=0;j<a;j++)
for(int y=0;y<25;y++)
c=a+b;
* can be replace by a
* can be replace by a sequence of characters as mentioned by the question. Can the sequence of characters be a null sequence also?
That is specifically
That is specifically mentioned in the problem statement.
Stephen can you clear my
Stephen can you clear my doubt?
I bet i only try to improve my programming skills , not cheat myself.
The time limit is 2 seconds.
The time limit is 2 seconds.
@Praveen Submit code for any
@Praveen Submit code for any of the problems and this information should then be updated.
Ya done Admin. I am seeing it
Ya done Admin. I am seeing it now.Thanks
There seems to be blank lines
There seems to be blank lines in the input that could, but should not, be treated as words of length zero. Have I got that right?
Are there empty lines in
Are there empty lines in input that should be processed ?
It looks like there are empty
It looks like there are empty lines that should NOT be processed. When I allowed for empty words (which the problem statement doesn't exclude) I got a wrong answer. Ignoring blank lines works.
Yup.. ignoring blank lines
Yup.. ignoring blank lines worked..
@ admin .. even my name doesn't show up in the rank list
I believe it is showing up
I believe it is showing up now. It takes a bit of time for the rank list to be updated after submission of a solution.
I m getting Wrong answer
I m getting Wrong answer again and again and I am sure its because I m using "gets()".
scanf() is too slow.
Can someone pls suggest me what shall I do to speedily read a sentence from input???
vvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvv repeated 55000 times and v*v*v repeated 300 times would be the worst case
I think vvvvvvvvvvvvvvvvvvvvvvvvv is 25 characters long
so it will take 55000X300X25 units of time at min.
for more than 2 test cases it will take more than 2 secs?
Isn't the time limit less than what shud be?
eg:
int a=55000,b=300,i,j,c;
for(int test=0;test<3;test++)
for(i=0;i<b;i++)
for(j=0;j<a;j++)
for(int y=0;y<25;y++)
c=a+b;
i downloaded the successful submission after the contest was over ,
that succesful submission gave more than 10 s to give solution for above input case.
my program takes 5-6 s for the above input case and same matching algo with some improvisation.
even so it shows TLE , PLZ tel me why?
Stephen ,, plz clarify . . . .