#P3375. 【模板】KMP
【模板】KMP
Description
Given two strings and , if the substring of on the interval is exactly the same as , then is said to occur in , and its occurrence position is .
Now please find all occurrence positions of in .
Define the border of a string as a substring of that is not the whole , and satisfies that is both a prefix and a suffix of .
For , you also need to compute, for each of its prefixes , the length of the longest border .
Input Format
The first line contains a string, which is .
The second line contains a string, which is .
Output Format
First output several lines, each with an integer, output the occurrence positions of in in increasing order.
The last line outputs integers, where the -th integer denotes the length of the longest border of the prefix of with length .
ABABABC
ABA
1
3
0 0 1
Hint
Explanation for Sample 1
.
For the length- prefix ABA of , the string A is both its suffix and its prefix, and it is the longest one, so the longest border length is .
Constraints and Notes
This problem uses bundled test points, with 4 subtasks.
- Subtask 0 (30 points): , .
- Subtask 1 (40 points): , .
- Subtask 2 (30 points): No special constraints.
- Subtask 3 (0 points): Hack.
For all test points, it is guaranteed that , and both and contain only uppercase English letters.
Translated by ChatGPT 5
京公网安备 11011102002149号