#5996. [CERC 2022] Insertions

[CERC 2022] Insertions

[CERC 2022] Insertions

题目描述

We are given three strings, $s$, $t$ and $p$. We will denote the length of a string by vertical bars, thus $|s|$ is the length of $s$ and so on. If we insert $t$ into $s$ at position $k$, where $0 \leq k \leq |s|$, the result is a new string consisting of the first $k$ characters of $s$, followed by the entirety of $t$, and finally followed by the remaining $|s| - k$ characters of $s$. We would like to select $k$ so that the resulting new string will contain the largest possible number of occurrences of $p$ as a substring.

Thus, for example, inserting t=abat = \text{aba} into s=abs = \text{ab} at position k=0k = 0 results in the string abaab\text{abaab}; at k=1k = 1, in the string aabab\text{aabab}; and at k=2k = 2, in the string ababa\text{ababa}. If we are interested in occurrences of p=abap = \text{aba}, then the best position to insert tt into ss is k=2k = 2, where we get two occurrences: ababa\text{ababa} and ababa\text{ababa} (as this example shows, occurrences of pp are allowed to overlap). If, on the other hand, we were interested in occurrences of p=aap = \text{aa}, then the best choices of kk would be k=0k = 0 and k=1k = 1, which result in one occurrence of pp, whereas k=2k = 2 results in 0 occurrences of pp.

输入格式

The first line contains the string $s$, the second line the string $t$, and the third line the string $p$.

输出格式

Output one line containing the following four integers, separated by spaces:
  1. The maximum number of occurrences of pp we can get after inserting tt into ss at position kk, if we choose the position kk wisely.
  2. The number of different kk's (from the range 0,1,…,∣s∣0, 1, \ldots, |s|) where this maximum number of occurrences of pp is attained.
  3. The minimum value of kk where the maximum number of occurrences of pp is attained.
  4. The maximum value of kk where the maximum number of occurrences of pp is attained.
ab
aba
aba
2 1 2 2
abaab
aba
ababa
1 3 1 5
eeoeo
eoe
eeo
2 3 1 4

提示

### Comment

The first of these three examples is the one discussed earlier in the problem statement

Input limits

  • 1≤∣s∣≤1051 \leq |s| \leq 10^5
  • 1≤∣t∣≤1051 \leq |t| \leq 10^5
  • 1≤∣p∣≤1051 \leq |p| \leq 10^5
  • All the strings consist only of lowercase letters of the English alphabet. 标签: P13812|树状数组|2022|KMP 算法|ICPC|CERC

来源

P13812|[CERC 2022] Insertions