#P7469. [NOI Online 2021 提高组] 积木小赛
[NOI Online 2021 提高组] 积木小赛
Problem Description
Alice and Bob have recently become keen on playing a game called the “Brick Mini Contest”.
Initially, Alice and Bob each have bricks arranged in a row from left to right, and each brick is labeled with a lowercase English letter.
Alice may discard any number of bricks from her own row (she may also discard none). Bob may discard a consecutive segment of bricks from the left end and a consecutive segment of bricks from the right end (he may discard from only one side, or discard none from both sides). Neither of them is allowed to discard all of their bricks. Then Alice and Bob will each re-form their remaining bricks into a row, keeping the original order.
Alice and Bob are busy playing, so they ask you to compute how many different situations result in their final remaining rows being identical.
Two rows of bricks are identical if and only if they have the same number of bricks and the letter at each position is the same.
Two situations are different if and only if the remaining bricks of Alice (or Bob) are different between the two situations.
Input Format
The first line contains a positive integer , the number of bricks.
The second line contains a lowercase string of length , representing Alice’s initial row of bricks. The -th character is the letter on the -th brick.
The third line contains a lowercase string of length , representing Bob’s initial row of bricks. The -th character is the letter on the -th brick.
Output Format
Output one line containing a non-negative integer, the answer.
5
bcabc
bbcca
9
20
egebejbhcfabgegjgiig
edfbhhighajibcgfecef
34
Hint
For all test points: , and and contain only lowercase English letters.
Test point satisfies: , and and each contain only one kind of letter.
Test points satisfy: .
Test points satisfy: .
Test points satisfy: .
Thanks to w33z8kqrqk8zzzx33 for providing the testdata.
Translated by ChatGPT 5