Anthem of Berland
HardRating 2300CodeforcesString Algorithms (KMP, Z, Hashing)
Approach hintTry it first, then revealHide
Let dp[i] be the best count when an occurrence of t ends at position i. The previous occurrence either ends at or before i - |t|, handled by a prefix maximum, or overlaps through a border of t found with the prefix function.