AT_abc456_c.Not Adjacent
普及-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string S consisting of a, b, c.
Find the number of non-empty substrings of S in which no two adjacent characters are the same, modulo 998244353.
Two substrings are considered distinct if they are taken from different positions, even if they are identical as strings.
What is a substring? A substring of S is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of S. For example, ab is a substring of abc, but ac is not a substring of abc.
给你一个仅由字符 a、b、c 组成的字符串 S。
请计算 S 的非空子串中,满足“任意两个相邻字符均不相同”的子串个数,并对 998244353 取模。
即使两个子串作为字符串完全相同,只要它们在 S 中起始或结束位置不同,就视为不同的子串。
什么是子串?字符串 S 的一个子串是指从 S 的开头删除零个或多个字符、并从 S 的末尾删除零个或多个字符后所得到的字符串。例如,ab 是 abc 的一个子串,但 ac 不是 abc 的子串。
输入格式
The input is given from Standard Input in the following format:
S
输入从标准输入中以如下格式给出:
S
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
abbc
输出#1
6
输入#2
cabcabcbcaccacbcbcaabacbacaabccacbccbcacbacbacabcacabcaccaaaaabababcbabacaccabbcacbcbcbcababcbcbabca
输出#2
760
说明/提示
Sample 1 Explanation:
The substrings in which no two adjacent characters are the same are the following six:
a(from the 1st to the 1st character of S)b(from the 2nd to the 2nd character of S)b(from the 3rd to the 3rd character of S)c(from the 4th to the 4th character of S)ab(from the 1st to the 2nd character of S)bc(from the 3rd to the 4th character of S)
Note that, as with the 2nd and 3rd entries, two substrings are considered distinct if they are taken from different positions, even if they are identical as strings.
Constraints
- S is a string of length between 1 and 3×105, inclusive, consisting of
a,b,c.
样例 1 解释:
满足“任意两个相邻字符均不相同”这一条件的子串共有以下六个:
a(取自字符串 S 的第 1 个到第 1 个字符)b(取自字符串 S 的第 2 个到第 2 个字符)b(取自字符串 S 的第 3 个到第 3 个字符)c(取自字符串 S 的第 4 个到第 4 个字符)ab(取自字符串 S 的第 1 个到第 2 个字符)bc(取自字符串 S 的第 3 个到第 4 个字符)
注意:如第 2 项和第 3 项所示,即使两个子串作为字符串完全相同,只要它们在原字符串中起始或结束位置不同,即视为不同的子串。
限制条件
- S 是一个仅由字符
a、b、c组成的字符串,其长度在 1 到 3×105(含)之间。
输入解题思路,AI测评打分。不知道怎么写?