#P3318. [SDOI2015] 双旋转字符串
[SDOI2015] 双旋转字符串
Description
Given two sets of strings and . All strings in have length exactly , and all strings in have length exactly . Moreover, is even.
If we denote all strings in by , and all strings in by , we want to know how many pairs satisfy that the concatenation has the double rotation property.
An even-length string can be written as the concatenation of two strings of equal length, i.e., . If can be obtained from by a rotation (cyclic shift), then is said to have the double rotation property. For example, the string vijos can be rotated to ijosv, josvi, osvij, or svijo. Thus, vijosjosvi has the double rotation property.
Input Format
The first line contains four positive integers , denoting respectively the size of set , the size of set , the length of strings in , and the length of strings in .
The next lines each contain a string , . Each string has length exactly , and consists only of the 26 lowercase letters.
The next lines each contain a string , . Each string has length exactly , and consists only of the 26 lowercase letters.
Output Format
Output a single integer, the number of pairs that satisfy the requirement.
4 4 7 3
vijosvi
josvivi
vijosos
ijosvsv
jos
vij
ijo
jos
6
Hint
For of the testdata, , , , .
For of the testdata, , , , .
For of the testdata, $2 \le N \times Total_S + M \times Total_T \le 4 \times 10^5$.
For of the testdata, $2 \le N \times Total_S + M \times Total_T \le 4 \times 10^6$.
Translated by ChatGPT 5
京公网安备 11011102002149号