Any one solved C2 of last contest with Divide and Conquer FFT?

Revision en1, by AIZtheUrizen, 2025-09-09 04:53:58

In the last round (round 1048), I solved the (2138C2) Maple and Tree Beauty (Hard Version) using divide and conquer method and NTT. The problem could be solved by doing binary search on the length of the LCS. But to do that every search I would have to calculate NTT using divide and conquer technique which would get me TLE.

To bypass this repeated calculation I tried a modified method of DnC. At first I calculated the NTT for the left subrange for divide and conquer. Afterwards I checked if I only considered the left subrange and could get a common prefix string of that range for the tree. If I could, then I moved to the right subrange, otherwise move to the left subrange. And afterwards repeatedly execute this process by dividing that subrange into left and right. This made sure that I am calculating divide and conquer NTT for the at most twice for each subrange of DnC. However, that also meant that the other half wouldn't be traversed. Making it equivalent to calculating the answer for the whole tree just once.

This was definitely a overkill and not the intended solution, but I knew it could be solved with DnC NTT so I just did. It was fun doing so. Did anyone else try the same idea?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English AIZtheUrizen 2025-09-09 05:17:02 239
en1 English AIZtheUrizen 2025-09-09 04:53:58 1272 Initial revision (published)