AT_abc456_d.Not Adjacent 2
普及-
通过率: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 subsequences of S in which no two adjacent characters are the same, modulo 998244353.
Two subsequences are considered distinct if they are taken from different positions, even if they are identical as strings.
What is a subsequence? A subsequence of S is a string obtained by removing zero or more characters from S and concatenating the remaining characters in their original order. For example, ab, ac are subsequences of abc, but ca, bb are not subsequences of abc.
给你一个仅由字符 a、b、c 组成的字符串 S。
请你计算 S 的非空子序列中,满足任意两个相邻字符均不相同的子序列个数,并对 998244353 取模。
即使两个子序列作为字符串完全相同,只要它们是从原字符串中不同位置选取的,就视为不同的子序列。
什么是子序列?字符串 S 的一个子序列是指从 S 中删除零个或多个字符后,将剩余字符按其在 S 中的原始顺序拼接而成的字符串。例如,ab 和 ac 都是 abc 的子序列,但 ca 和 bb 不是 abc 的子序列。
输入格式
The input is given from Standard Input in the following format:
S
输入从标准输入中以如下格式给出:
S
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
abbc
输出#1
11
输入#2
cabcabcbcaccacbcbcaabacbacaabccacbccbcacbacbacabcacabcaccaaaaabababcbabacaccabbcacbcbcbcababcbcbabca
输出#2
378217423
说明/提示
Sample 1 Explanation:
The subsequences in which no two adjacent characters are the same are the following 11:
a(the 1st character of S)b(the 2nd character of S)b(the 3rd character of S)c(the 4th character of S)ab(the 1st, 2nd characters of S)ab(the 1st, 3rd characters of S)ac(the 1st, 4th characters of S)bc(the 2nd, 4th characters of S)bc(the 3rd, 4th characters of S)abc(the 1st, 2nd, 4th characters of S)abc(the 1st, 3rd, 4th characters of S)
Note that, as with the 2nd and 3rd entries, two subsequences are considered distinct if they are taken from different positions, even if they are identical as strings.
Sample 2 Explanation:
Output the count modulo 998244353.
Constraints
- S is a string of length between 1 and 3×105, inclusive, consisting of
a,b,c.
样例 1 解释:
满足“任意两个相邻字符均不相同”这一条件的子序列共有以下 11 个:
a(取自 S 的第 1 个字符)b(取自 S 的第 2 个字符)b(取自 S 的第 3 个字符)c(取自 S 的第 4 个字符)ab(取自 S 的第 1、2 个字符)ab(取自 S 的第 1、3 个字符)ac(取自 S 的第 1、4 个字符)bc(取自 S 的第 2、4 个字符)bc(取自 S 的第 3、4 个字符)abc(取自 S 的第 1、2、4 个字符)abc(取自 S 的第 1、3、4 个字符)
注意:如第 2 和第 3 项所示,即使两个子序列作为字符串完全相同,只要它们取自原字符串中不同的位置,即视为不同的子序列。
样例 2 解释:
输出结果对 998244353 取模。
约束条件
- S 是一个仅由字符
a、b、c组成的字符串,其长度在 1 到 3×105(含)之间。
输入解题思路,AI测评打分。不知道怎么写?