https://www.hackerrank.com/contests/university-codesprint-5/challenges/marmelade-kingdom I am not able to understand the editorial can someone explain a bit in detail.
# | 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 | 170 |
2 | Um_nik | 162 |
3 | atcoder_official | 161 |
4 | maomao90 | 160 |
5 | djm03178 | 158 |
5 | -is-this-fft- | 158 |
7 | Dominater069 | 156 |
8 | adamant | 154 |
9 | luogu_official | 153 |
10 | awoo | 152 |
https://www.hackerrank.com/contests/university-codesprint-5/challenges/marmelade-kingdom I am not able to understand the editorial can someone explain a bit in detail.
Name |
---|
you can easily deduce that the solution is Dynamic Programming where dp[u] equals str[u] + the lexicographically minimum dp[v] where there is an edge going from u to v however doing that with strings will easily cause you a very shiny time limit exceeded.
so he is representing the string saved in dp[v] as a segment tree that carries the string hash of a range however finding the minimum between two strings is not that easy hence the hash comes into play he binary search the maximum prefix where hash1[x][0 - > i] = hash[y][0 - > i] now the next character should be the one you decide for which is less x or y.
but that is also going to give a very shiny memory limit exceeded before it gives you a time limit exceeded hence the use of persistent segment tree where you can say that tree[u] = update(tree[v]) this assigns the value of tree[v] to tree[u] with the modification that is add str[u] to segment tree of v
Thank you for the beautiful explanation. I didn't understand the segment tree part. Are we making separate segment tree for each node? If not then how it is assured that the nodes which have an incoming edge to current nodes are in a sequence.
yes there is a segment tree for each node that's the idea of persistent segment trees they help you do that efficiently.
you can read about them here
Thanks I got it :)