問題一覧 > 通常問題

No.3500 01 String

レベル : / AI推定難易度 : 1300 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 125
作問者 : rhoo / テスター : Naru820 Nzt3 Solalyth
お気に入りにしたユーザー ProblemId : 13158 / 自分の提出
問題文最終更新日: 2026-04-14 14:57:40
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
CPCTF 2026: PPC (順位表) の他の問題:

Problem Statement

traP has a workshop called the 0→1 Workshop for beginners in digital creation.

You are given a string $A$ of length $N$ consisting of $0$ and $1$. The $i$-th element ($1 \le i \le N$) of the string is denoted by $A_i$.
Consider the following operation on this string.

  • Choose an integer $i$ satisfying $1 \le i \le N$.
  • If $A_i = 0$ and $i < N$, set $A_{i+1}$ to $0$.
  • If $A_i = 1$ and $i > 1$, set $A_{i-1}$ to $1$.

Output the number of strings that can be obtained from the string $A$ by performing this operation $0$ or more times, modulo $998244353$.

Constraints

  • $1 \le N \le 5 \times 10^5$
  • $A$ is a string of length $N$ consisting only of $0,1$

Input

The input is given from standard input in the following format.

$N$
$A$

Output

Output the desired count modulo $998244353$ on 1 line.

Sample

Sample 1
Input
2
01
Output
3

The reachable strings are the following 3: 01, 00, 11.

Sample 2
Input
4
1111
Output
1

The string does not change no matter which position is chosen, so the only reachable string is 1111, which is 1 string.

Sample 3
Input
42
010100101010101010110101000101101100101001
Output
211079167

Output the answer modulo $998244353$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。