This counts as a general application of the generalized suffix automaton. We can do this the same way as counting over multiple strings, except that while running the DFS on the tree we need to record the SAM node at each branching point, and then backtrack. The rest, the method for counting distinct substrings, is a very standard trick.
Continue reading →Chinese original · English translation by Claude Opus 5.5
Take the first \(k\) digits as the repeating block, and compare it against each following block of length \(k\); if the first block is smaller, just add one to it.
Continue reading →Chinese original · English translation by Claude Opus 5.5
We notice that we only need to make sure that at any moment the number of \(0\)s is greater than or equal to the number of colors. Directly considering stuffing the balls in one by one means dealing not only with the issue of identical balls but also with the concrete arrangement of colors, which is a real pain, so instead let's place all the balls on the sequence in one go: let \(dp[i][j]\) be the state with \(i\) \(0\)s and \(j\) colors, and we can transition like this:
The suffix automaton is a powerful tool for handling string information. A suffix automaton is stored on a trie, and together with the Link pointers it can be regarded as a DAG. Any path starting from the origin can be regarded as a substring of the string, and no duplicate substring information exists on a suffix automaton (however, we can make some extensions to maintain substring position information).
Continue reading →Chinese original · English translation by Claude Opus 5.5