A12340 | Substring Removal
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a string $s$ of length $n$ consisting only of lowercase Latin letters.
A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.
Your task is to calculate the number of ways to remove exactly one substring from this string in such a way that all remaining characters are equal (the number of distinct characters either zero or one).
It is guaranteed that there is at least two different characters in $s$ .
Note that you can remove the whole string and it is correct. Also note that you should remove at least one character.
Since the answer can be rather large (not very large though) print it modulo $998244353$ .
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.
Your task is to calculate the number of ways to remove exactly one substring from this string in such a way that all remaining characters are equal (the number of distinct characters either zero or one).
It is guaranteed that there is at least two different characters in $s$ .
Note that you can remove the whole string and it is correct. Also note that you should remove at least one character.
Since the answer can be rather large (not very large though) print it modulo $998244353$ .
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
输入格式
The first line of the input contains one integer $n$ ( $2 \le n \le 2 \cdot 10^5$ ) — the length of the string $s$ .
The second line of the input contains the string $s$ of length $n$ consisting only of lowercase Latin letters.
It is guaranteed that there is at least two different characters in $s$ .
The second line of the input contains the string $s$ of length $n$ consisting only of lowercase Latin letters.
It is guaranteed that there is at least two different characters in $s$ .
输出格式
Print one integer — the number of ways modulo $998244353$ to remove exactly one substring from $s$ in such way that all remaining characters are equal.
输入输出样例
输入 #1
4 abaa
输出 #1
6
输入 #2
7 aacdeee
输出 #2
6
输入 #3
2 az
输出 #3
3
Let $s[l; r]$ be the substring of $s$ from the position $l$ to the position $r$ inclusive.
Then in the first example you can remove the following substrings:
- $s[1; 2]$ ;
- $s[1; 3]$ ;
- $s[1; 4]$ ;
- $s[2; 2]$ ;
- $s[2; 3]$ ;
- $s[2; 4]$ .
In the second example you can remove the following substrings:
- $s[1; 4]$ ;
- $s[1; 5]$ ;
- $s[1; 6]$ ;
- $s[1; 7]$ ;
- $s[2; 7]$ ;
- $s[3; 7]$ .
In the third example you can remove the following substrings:
- $s[1; 1]$ ;
- $s[1; 2]$ ;
- $s[2; 2]$ .
Then in the first example you can remove the following substrings:
- $s[1; 2]$ ;
- $s[1; 3]$ ;
- $s[1; 4]$ ;
- $s[2; 2]$ ;
- $s[2; 3]$ ;
- $s[2; 4]$ .
In the second example you can remove the following substrings:
- $s[1; 4]$ ;
- $s[1; 5]$ ;
- $s[1; 6]$ ;
- $s[1; 7]$ ;
- $s[2; 7]$ ;
- $s[3; 7]$ .
In the third example you can remove the following substrings:
- $s[1; 1]$ ;
- $s[1; 2]$ ;
- $s[2; 2]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted