아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Incredibly Cute Penguin Chicks

시간 제한6초메모리 제한1024 MB

요약
C, I, P로 이루어진 문자열을, 두 문자의 개수가 같고 나머지 한 문자가 더 많은 조각들로 나누는 방법의 수를 998244353으로 나눈 나머지로 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 조합론, 문자열
정답자
아직 제출이 없습니다

문제

The Incredibly Cute Penguin Chicks love to eat worms. One day, their mother found a long string-shaped worm with a number of letters on it. She decided to cut this worm into pieces and feed the chicks.

The chicks somehow love International Collegiate Programming Contest and want to eat pieces with ICPC-ish character strings on them. Here, a string is ICPC-ish if the following conditions hold.

  • It consists of only C’s, I’s, and P’s.
  • Two of these three characters appear the same number of times (possibly zero times) in the string and the remaining character appears strictly more times.

For example, ICPC and PPPPPP are ICPC-ish, but PIC, PIPCCC and PIPE are not.

You are given the string on the worm the mother found. The mother wants to provide one or more parts of the worm all with an ICPC-ish string, without wasting remains. Your task is to count the number of ways the worm can be prepared in such a manner.

입력

The input is a single line containing a character string SS consisting of only C’s, I’s, and P’s, which is on the string-shaped worm the mother penguin found. The length of SS is between 11 and 10610^6, inclusive.

출력

Print in a line the number of ways to represent the string S as a concatenation of one or more ICPC-ish strings modulo a prime number 998,244,353=223×7×17+1998\\,244\\,353 = 2^{23} \times 7 \times 17 + 1.

힌트

In the first sample, the string “ICPC” can be represented in the following two ways.

  • A single ICPC-ish string, “ICPC”.
  • Concatenation of four ICPC-ish strings, “I”, “C”, “P”, and “C”.

예제3

  1. 예제 1

    입력
    ICPC
    
    예상 출력
    2
    
  2. 예제 2

    입력
    CCCIIIPPP
    
    예상 출력
    69
    
  3. 예제 3

    입력
    PICCICCIPPI
    
    예상 출력
    24