AT_abc456_d.Not Adjacent 2

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string SS consisting of a, b, c.

Find the number of non-empty subsequences of SS in which no two adjacent characters are the same, modulo 998244353998244353.

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 SS is a string obtained by removing zero or more characters from SS 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 组成的字符串 SS。

请你计算 SS 的非空子序列中,满足任意两个相邻字符均不相同的子序列个数,并对 998244353998244353 取模。

即使两个子序列作为字符串完全相同,只要它们是从原字符串中不同位置选取的,就视为不同的子序列。

什么是子序列?字符串 SS 的一个子序列是指从 SS 中删除零个或多个字符后,将剩余字符按其在 SS 中的原始顺序拼接而成的字符串。例如,ab 和 ac 都是 abc 的子序列,但 ca 和 bb 不是 abc 的子序列。

输入格式

The input is given from Standard Input in the following format:

SS

输入从标准输入中以如下格式给出:

SS

输出格式

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 1111:

  • a (the 11st character of SS)
  • b (the 22nd character of SS)
  • b (the 33rd character of SS)
  • c (the 44th character of SS)
  • ab (the 11st, 22nd characters of SS)
  • ab (the 11st, 33rd characters of SS)
  • ac (the 11st, 44th characters of SS)
  • bc (the 22nd, 44th characters of SS)
  • bc (the 33rd, 44th characters of SS)
  • abc (the 11st, 22nd, 44th characters of SS)
  • abc (the 11st, 33rd, 44th characters of SS)

Note that, as with the 22nd and 33rd 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 998244353998244353.

Constraints

  • SS is a string of length between 11 and 3×1053 \times 10^5, inclusive, consisting of a, b, c.

样例 1 解释:
满足“任意两个相邻字符均不相同”这一条件的子序列共有以下 1111 个:

  • a(取自 SS 的第 11 个字符)
  • b(取自 SS 的第 22 个字符)
  • b(取自 SS 的第 33 个字符)
  • c(取自 SS 的第 44 个字符)
  • ab(取自 SS 的第 11、22 个字符)
  • ab(取自 SS 的第 11、33 个字符)
  • ac(取自 SS 的第 11、44 个字符)
  • bc(取自 SS 的第 22、44 个字符)
  • bc(取自 SS 的第 33、44 个字符)
  • abc(取自 SS 的第 11、22、44 个字符)
  • abc(取自 SS 的第 11、33、44 个字符)

注意:如第 22 和第 33 项所示,即使两个子序列作为字符串完全相同,只要它们取自原字符串中不同的位置,即视为不同的子序列。

样例 2 解释:
输出结果对 998244353998244353 取模。

约束条件

  • SS 是一个仅由字符 a、b、c 组成的字符串,其长度在 11 到 3×1053 \times 10^5(含)之间。

输入解题思路,AI测评打分。不知道怎么写?

首页