AtCoder Beginner Contest 338
G
evall
AtCoder
⌀ 2573
原题
翻译中…

Problem Statement

翻译中…

You are given a string $S$. Each character of $S$ is one of 123456789+*, and the first and last characters of $S$ are digits. There are no adjacent non-digit characters in $S$.

翻译中…

For a pair of integers $i, j$ ($1 \leq i \leq j \leq |S|$), we define $\mathrm{eval}(S_{i..j})$ as follows:

翻译中…
  • If both the $i$-th and $j$-th characters of $S$ are digits, then $\mathrm{eval}(S_{i..j})$ is the result of evaluating the $i$-th to the $j$-th characters (inclusive) of $S$ as a usual arithmetic expression (where * represents multiplication). For example, if $S =$ 1+2*151, then $\mathrm{eval}(S_{1..6}) = 1 + 2 \times 15 = 31$.
  • Otherwise, $\mathrm{eval}(S_{i..j})$ is zero.
翻译中…

Find ${\displaystyle \sum_{i=1}^{|S|} \sum_{j=i}^{|S|} \mathrm{eval}(S_{i..j})}$, modulo $998244353$.

翻译中…

Constraints

翻译中…
  • $1 \leq |S| \leq 10^6$
  • Each character of $S$ is one of 123456789+*.
  • The first and last characters of $S$ are digits.
  • There are no adjacent non-digit characters in $S$.
翻译中…

Input

翻译中…

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

翻译中…

S

翻译中…

Output

翻译中…

Print ${\displaystyle \sum_{i=1}^{|S|} \sum_{j=i}^{|S|} \mathrm{eval}(S_{i..j})}$, modulo $998244353$.

翻译中…

样例

Input #1
1+2*34
Output #1
197
The cases where $\mathrm{eval}(S_{i..j})$ is not zero are as follows: - $\mathrm{eval}(S_{1..1}) = 1$ - $\mathrm{eval}(S_{1..3}) = 1 + 2 = 3$ - $\mathrm{eval}(S_{1..5}) = 1 + 2 \times 3 = 7$ - $\mathrm{eval}(S_{1..6}) = 1 + 2 \times 34 = 69$ - $\mathrm{eval}(S_{3..3}) = 2$ - $\mathrm{eval}(S_{3..5}) = 2 \times 3 = 6$ - $\mathrm{eval}(S_{3..6}) = 2 \times 34 = 68$ - $\mathrm{eval}(S_{5..5}) = 3$ - $\mathrm{eval}(S_{5..6}) = 34$ - $\mathrm{eval}(S_{6..6}) = 4$ The sum of these is $1+3+7+69+2+6+68+3+34+4 = 197$.
Input #2
338*3338*33338*333338+3333338*33333338+333333338
Output #2
527930018
题目信息
题号
abc338_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。