# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Name |
---|
Your code doesn't always find the lexicographically smallest word. For example, consider the following input...
Your code outputs "aabc", when the correct answer is "aaabc".
well, how can it be done when I'm adding the words in reverse order ??
because I'm confused with a test case like this:
a aa aaa
a
The correct answer in that case is "aa".
I haven't thought of a good solution yet. Apparently there can be up to 5 million letters in the whole input, so traversing the whole tree for every word will be too slow. I designed an algorithm like that and tried it out to check the speed, but stupid SPOJ is giving me wrong answer, as usual, probably because there's an extra newline, a missing new line or a mosquito flew by.
I tried every possible input I found on the Internet and my program always gives the right answer, but yet the crystal delicate SPOJ checker is giving me WA.
Then there's the easier solution of mapping every suffix to the shortest word that matches using map...
But it can be solved using trie too, reversing all words and storing at every node of the trie the two minimal words that are contained in that subtree (two are required in case one of them is the prefix we are looking itself).