CF1499E.Chaotic Merge
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two strings x and y , both consist only of lowercase Latin letters. Let ∣s∣ be the length of string s .
Let's call a sequence a a merging sequence if it consists of exactly ∣x∣ zeros and exactly ∣y∣ ones in some order.
A merge z is produced from a sequence a by the following rules:
- if ai=0 , then remove a letter from the beginning of x and append it to the end of z ;
- if ai=1 , then remove a letter from the beginning of y and append it to the end of z .
Two merging sequences a and b are different if there is some position i such that ai=bi .
Let's call a string z chaotic if for all i from 2 to ∣z∣ zi−1=zi .
Let s[l,r] for some 1≤l≤r≤∣s∣ be a substring of consecutive letters of s , starting from position l and ending at position r inclusive.
Let f(l1,r1,l2,r2) be the number of different merging sequences of x[l1,r1] and y[l2,r2] that produce chaotic merges. Note that only non-empty substrings of x and y are considered.
Calculate 1≤l1≤r1≤∣x∣1≤l2≤r2≤∣y∣∑f(l1,r1,l2,r2) . Output the answer modulo 998244353 .
输入格式
The first line contains a string x ( 1≤∣x∣≤1000 ).
The second line contains a string y ( 1≤∣y∣≤1000 ).
Both strings consist only of lowercase Latin letters.
输出格式
Print a single integer — the sum of f(l1,r1,l2,r2) over 1≤l1≤r1≤∣x∣ and 1≤l2≤r2≤∣y∣ modulo 998244353 .
输入输出样例
输入#1
aaa bb
输出#1
24
输入#2
code forces
输出#2
1574
输入#3
aaaaa aaa
输出#3
0
输入#4
justamassivetesttocheck howwellyouhandlemodulooperations
输出#4
667387032
说明/提示
In the first example there are:
- 6 pairs of substrings "a" and "b", each with valid merging sequences "01" and "10";
- 3 pairs of substrings "a" and "bb", each with a valid merging sequence "101";
- 4 pairs of substrings "aa" and "b", each with a valid merging sequence "010";
- 2 pairs of substrings "aa" and "bb", each with valid merging sequences "0101" and "1010";
- 2 pairs of substrings "aaa" and "b", each with no valid merging sequences;
- 1 pair of substrings "aaa" and "bb" with a valid merging sequence "01010";
Thus, the answer is 6⋅2+3⋅1+4⋅1+2⋅2+2⋅0+1⋅1=24 .