The Cypriote Mermaid

시간 제한1초메모리 제한2048 MB

요약
물음표를 0이나 1로 바꿔 만든 이진 문자열 가운데, 같은 색 인접 구슬 두 개를 지우는 연산을 반복해 전부 없앨 수 있는 경우의 수를 구한다.
난이도

어려움10점 중 8점

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

문제

Every summer Stelinuța goes to Cyprus for an 11-day programming camp, and while being there, she loves to go swimming and snorkeling in the sea.

One day, when she was snorkeling, she found a very interesting pearl necklace: a straight (non-cyclic) thread with pearls on it. Originally, all the pearls had to be either black or white. However, some pearls were so damaged that she couldn't even distinguish their original color.

From that, Stelinuța came up with an idea: imagine that you can remove any two adjacent pearls that have the same color from the necklace. She is curious to know in how many different ways the original necklace could have looked so that, after applying that operation any number of times, she could end up with an empty necklace. As the answer may be very large, it is sufficient to find it modulo 998,244,353998\\,244\\,353.

입력

The first line contains a string containing "1", "0" and "?" describing the necklace Stelinuța found. Each pearl is represented as follows:

  • "1": the pearl is black,
  • "0": the pearl is white,
  • "?": the original color is unknown.

The length of the string will be at least 11 and at most 2⋅1052 \cdot 10^{5}.

출력

Output a single integer: the number of different ways the necklace could have looked like modulo 998,244,353998\\,244\\,353.

힌트

In the given example, the only way the necklace could have looked like is "011110". We can remove "11" twice, and then remove the remaining "00" to get an empty necklace.

For all the remaining assignments, there is no way to remove all the pearls by repeatedly removing two adjacent pearls of the same color.

예제1

  1. 예제 1

    입력
    01?1??
    
    예상 출력
    1