ADAINDEX - Ada and Indexing
Ada the Ladybug has many things to do and almost no time. She wants to to save time while searching for something so she have decided to make a search engine.
She has many words in her TODO list. It costs her precious time to find out, whether a word is in it so she seeks your help. You will get list and some queries. You will be asked, to find out how many words in TODO list have a word as prefix.
Input
The first line contains N, Q: the number words in TODO list and number of queries.
N lines follow, with words (of TODO list) consisting of lowercase letters. The sum of their lengths won't be greater than 106
Q lines follow, with words (queries) consisting of lowercase letters. The sum of their lengths won't be greater than 106
Output
For each query print the number of words in TODO list which have actual word as prefix.
Example Input
12 6 bulldog dog dogged doggedly doggerel dogma dogmatic dogmatism dogs catastroph catastroph doctor cat dog dogg do doctrinography dogge
Example Output
2 8 3 9 0 3
hide comments
cardinalx:
2019-04-09 12:44:24
can solve it with hashing Last edit: 2019-04-09 12:46:11 |
|
ameernsr:
2019-04-09 12:07:19
badihi
|
|
DOT:
2018-09-13 17:42:38
Easy question. AC in one go! |
|
julkas:
2018-08-04 16:33:56
Not only Trie. Try other data structure or algorithm. Last edit: 2018-08-05 10:21:23 |
|
singlasahil221:
2018-05-17 06:57:16
AC in one go. Easy implementation of Trie. |
|
flyingduchman_:
2017-12-12 13:42:42
You don't need bool isEndOfWord as there is no delete operation required, instead use a counter variable for each node to smoothly handle duplicates. While inserting, increment the counter variable, thus duplicates will be counted. |
|
avik26091998:
2017-11-22 20:09:02
Good problem for data structure implementation... |
|
artful_dodger:
2017-10-19 19:17:32
@morass ... My submission in CPP14 times out (test 15) but in clang CPP it passes with 3.74 sec. Any idea why this might happen ? |
|
caohoangtung:
2017-09-20 15:43:46
My first problem using trie :) AC in 1 go |
|
da_201501181:
2017-06-28 11:12:57
AC in one GO..!! Simple application of trie..! |
Added by: | Morass |
Date: | 2016-09-06 |
Time limit: | 6s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU |