#abc338g. G - evall

G - evall

Score: 600600 points

问题描述

给定一个字符串 SS,其每个字符为 123456789+* 中的一个,并且 SS 的首尾字符均为数字。在 SS 中不存在相邻的非数字字符。

对于一对整数 i,ji, j(满足 1ijS1 \leq i \leq j \leq |S|),我们定义 eval(Si..j)\mathrm{eval}(S_{i..j}) 如下:

  • 如果 SS 的第 ii 个和第 jj 个字符都是数字,则 eval(Si..j)\mathrm{eval}(S_{i..j}) 是将从第 ii 个到第 jj 个(包含)字符的 SS 当作常规算术表达式求值的结果(其中 * 表示乘法)。例如,如果 S=S = 1+2*151,则 eval(S1..6)=1+2×15=31\mathrm{eval}(S_{1..6}) = 1 + 2 \times 15 = 31
  • 否则,eval(Si..j)\mathrm{eval}(S_{i..j}) 等于零。

请计算 ${\displaystyle \sum_{i=1}^{|S|} \sum_{j=i}^{|S|} \mathrm{eval}(S_{i..j})}$ 并对 998244353998244353 取模后的结果。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

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

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

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

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

Constraints

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

Input

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

SS

Output

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

Sample Input 1

1+2*34

Sample Output 1

197

The cases where eval(Si..j)\mathrm{eval}(S_{i..j}) is not zero are as follows:

  • eval(S1..1)=1\mathrm{eval}(S_{1..1}) = 1
  • eval(S1..3)=1+2=3\mathrm{eval}(S_{1..3}) = 1 + 2 = 3
  • eval(S1..5)=1+2×3=7\mathrm{eval}(S_{1..5}) = 1 + 2 \times 3 = 7
  • eval(S1..6)=1+2×34=69\mathrm{eval}(S_{1..6}) = 1 + 2 \times 34 = 69
  • eval(S3..3)=2\mathrm{eval}(S_{3..3}) = 2
  • eval(S3..5)=2×3=6\mathrm{eval}(S_{3..5}) = 2 \times 3 = 6
  • eval(S3..6)=2×34=68\mathrm{eval}(S_{3..6}) = 2 \times 34 = 68
  • eval(S5..5)=3\mathrm{eval}(S_{5..5}) = 3
  • eval(S5..6)=34\mathrm{eval}(S_{5..6}) = 34
  • eval(S6..6)=4\mathrm{eval}(S_{6..6}) = 4

The sum of these is 1+3+7+69+2+6+68+3+34+4=1971+3+7+69+2+6+68+3+34+4 = 197.

Sample Input 2

338*3338*33338*333338+3333338*33333338+333333338

Sample Output 2

527930018

update @ 2024/3/10 01:30:32