鹿島建設プログラミングコンテスト2020 (AtCoder Regular Contest 110)
翻译中…
Problem Statement
翻译中…
We have a string $S$ of length $N$ consisting of A, B, and C.
翻译中…
You can do the following operation on $S$ zero or more times:
翻译中…
- Choose
$i$$(1 \leq i \leq |S| - 1)$such that$S_i \neq S_{i + 1}$. Replace$S_i$with the character (amongA,B, andC) that is different from both$S_i$and$S_{i + 1}$, and remove$S_{i + 1}$from$S$.
翻译中…
Find the number of distinct strings that $S$ can be after zero or more operations, and print the count modulo $(10^9+7)$.
翻译中…
Constraints
翻译中…
$1 \leq N \leq 10^6$$S$is a string of length$N$consisting ofA,B, andC.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N
S
翻译中…
Output
翻译中…
Print the number of distinct strings that $S$ can be after zero or more operations, modulo $(10^9+7)$.
翻译中…
样例
Input #1
5
ABAAC
Output #1
11
For example, the following sequence of operations turns $S$ into `ACB`:
- First, choose $i=2$. We replace $S_2$ with `C` and remove $S_3$, turning $S$ into `ACAC`.
- Then, choose $i=3$. We replace $S_3$ with `B` and remove $S_4$, turning $S$ into `ACB`.
Input #2
50
AACCCCBBBACCCCABABCCCCABACCACACACCACABABBBABABACCB
Output #2
256972022
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。