I tried to solve this problem 104375H, but i have no idea about how solve this efficiently. I need some help.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Название |
---|
Notice that since the total length of the string list is $$$2e5$$$, there are at most $$$\sqrt{4e5} = 632$$$ distinct lengths of string from the list. Therefore, for each string length $$$L$$$, you can check whether the substring $$$[i, i + L)$$$ is from the list. From there it's just simple dp. Worst case, the time complexity would be $$$632 * |S| * log N$$$, but with some optimization it would be closer to $$$632 * |S|$$$ (in fact I think this is the time complexity of this algorithm, but I can't prove it nor finding a test case to disprove it).
My AC solution: Code
Why are there 632 distinct lengths? if every |word| is maximum 1e5? I can't see the submission, "You are not allowed to view the requested page". And this is my submission (TLE of course xd)
-VIBE Assume that there are more than $$$632$$$ distinct lengths. Let's call those distinct lengths $$$L_1$$$, $$$L_2$$$, ..., $$$L_n$$$, such that $$$L_1 < L_2 < ... < L_n$$$. Then the minimum sum of lengths of those strings would be $$$L_1 + L_2 + ... + L_n \leq 1 + 2 + 3 + ... + n \leq 1 + 2 + 3 + ... + 633 = 200661$$$. Therefore the number of distinct lengths should be less than $$$633$$$.
Therefore, for each string length $$$L$$$, you can check whether the substring $$$[i,i+L)$$$ is in the list by binary searching in the list to find if there exist any string that has the same hash code as the substring.
Then it is just simple dp.
hey it is still giving me tle.Could you please tell me what am i doing wrongsubmission
got accepted by using unordered_set for the pair....this question has a very tight constraints...firstly i have to use two hash functions otherwise it was colliding and then this unordered set thing for pair...i didnt know that we have to use a custom hash function for using unordered_set.....overall learned many things from it
could you please explain a little bit more deep
I am pretty sure steveonalex idea works, but another interesting way you can solve this is by making a DP over the aho corasick automaton.
Yeah, I've solved problems like this in both way. I just think that my idea is way funnier, and more suitable for cyan (although it is kind of slow, so you need optimize it really hard).
I agree, it is just interesting to know other solutions and maybe learn something new along the way.