305829: CF1096B. Substring Removal
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Substring Removal
题意翻译
## Description 给定一个长度为 $n$ 的字符串,请你从中去除一个子串,使得剩下的串要么为空,要么字符完全相同,输出方案数模 $998244353$ ## Input 第一行是字符串长度 $n$ 下面一行是一个长度为 $n$ 的字符串 ## Output 输出一行一个整数,代表答案对 $998244353$ 取模的结果 ## Hint $2~\leq~n~\leq~2~\times~10^5$ 保证给出的字符串全是小写字母且至少含有两种字符 translated by 一扶苏一题目描述
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.输入输出格式
输入格式
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 $ .
输出格式
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