A16461 | Twin Friends
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You meet two new friends who are twins. The name of the elder twin is $A$ , which consists of $N$ characters. While the name of the younger twin is $B$ , which consists of $M$ characters. It is known that $N \leq M$ .
You want to call each of them with a nickname. For the elder twin, you want to pick any permutation of $A$ as the nickname. For the younger twin, you want to remove exactly $M - N$ characters from any permutation of $B$ . Denote the nicknames of the elder twin and the younger twin as $A'$ and $B'$ , respectively.
You want the nicknames to satisfy the following requirement. For each $i$ that satisfies $1 \leq i \leq N$ , $B'_i$ must be equal to either $A'_i$ or the next letter that follows alphabetically after $A'_i$ (if such a next letter exists).
Determine the number of different pairs of nicknames $(A', B')$ that satisfy the requirement. Two pairs of nicknames are considered different if at least one of the nicknames are different. As the result might be large, find the answer modulo $998\,244\,353$ .
You want to call each of them with a nickname. For the elder twin, you want to pick any permutation of $A$ as the nickname. For the younger twin, you want to remove exactly $M - N$ characters from any permutation of $B$ . Denote the nicknames of the elder twin and the younger twin as $A'$ and $B'$ , respectively.
You want the nicknames to satisfy the following requirement. For each $i$ that satisfies $1 \leq i \leq N$ , $B'_i$ must be equal to either $A'_i$ or the next letter that follows alphabetically after $A'_i$ (if such a next letter exists).
Determine the number of different pairs of nicknames $(A', B')$ that satisfy the requirement. Two pairs of nicknames are considered different if at least one of the nicknames are different. As the result might be large, find the answer modulo $998\,244\,353$ .
输入格式
The first line consists of two integers $N$ $M$ ( $1 \leq N \leq M \leq 200\,000$ ).
The second line consists of a string $A$ of length $N$ .
The third line consists of a string $B$ of length $M$ .
All strings consist of only upper-case letters.
The second line consists of a string $A$ of length $N$ .
The third line consists of a string $B$ of length $M$ .
All strings consist of only upper-case letters.
输出格式
Output a single integer representing number of different pairs $(A', B')$ that satisfy the requirement, modulo $998\,244\,353$ .
输入输出样例
输入 #1
3 4 AMA ANAB
输出 #1
9
输入 #2
5 8 BINUS BINANUSA
输出 #2
120
输入 #3
15 30 BINUSUNIVERSITY BINANUSANTARAUNIVERSITYJAKARTA
输出 #3
151362308
输入 #4
4 4 UDIN ASEP
输出 #4
0
Explanation for the sample input/output #1
The $9$ pairs are:
- (AAM, AAN),
- (AAM, ABN),
- (AAM, BAN),
- (AMA, ANA),
- (AMA, ANB),
- (AMA, BNA),
- (MAA, NAA),
- (MAA, NAB), and
- (MAA, NBA).
Explanation for the sample input/output #2
The $120$ pairs are the pairs where $A'$ is a permutation of BINUS and $B' = A'$ .
The $9$ pairs are:
- (AAM, AAN),
- (AAM, ABN),
- (AAM, BAN),
- (AMA, ANA),
- (AMA, ANB),
- (AMA, BNA),
- (MAA, NAA),
- (MAA, NAB), and
- (MAA, NBA).
Explanation for the sample input/output #2
The $120$ pairs are the pairs where $A'$ is a permutation of BINUS and $B' = A'$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted