Score: 600 points
问题描述
给定一个字符串 S,其每个字符为 123456789+* 中的一个,并且 S 的首尾字符均为数字。在 S 中不存在相邻的非数字字符。
对于一对整数 i,j(满足 1≤i≤j≤∣S∣),我们定义 eval(Si..j) 如下:
- 如果 S 的第 i 个和第 j 个字符都是数字,则 eval(Si..j) 是将从第 i 个到第 j 个(包含)字符的 S 当作常规算术表达式求值的结果(其中 *表示乘法)。例如,如果 S=1+2*151,则 eval(S1..6)=1+2×15=31。
- 否则,eval(Si..j) 等于零。
请计算 ${\displaystyle \sum_{i=1}^{|S|} \sum_{j=i}^{|S|} \mathrm{eval}(S_{i..j})}$ 并对 998244353 取模后的结果。
以上为通义千问 qwen-max 翻译,仅供参考。
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≤i≤j≤∣S∣), we define eval(Si..j) as follows:
- If both the i-th and j-th characters of S are digits, then eval(Si..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 eval(S1..6)=1+2×15=31.
- Otherwise, eval(Si..j) is zero.
Find ${\displaystyle \sum_{i=1}^{|S|} \sum_{j=i}^{|S|} \mathrm{eval}(S_{i..j})}$, modulo 998244353.
Constraints
- 1≤∣S∣≤106
- 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.
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.
1+2*34
Sample Output 1
197
The cases where eval(Si..j) is not zero are as follows:
- eval(S1..1)=1
- eval(S1..3)=1+2=3
- eval(S1..5)=1+2×3=7
- eval(S1..6)=1+2×34=69
- eval(S3..3)=2
- eval(S3..5)=2×3=6
- eval(S3..6)=2×34=68
- eval(S5..5)=3
- eval(S5..6)=34
- eval(S6..6)=4
The sum of these is 1+3+7+69+2+6+68+3+34+4=197.
338*3338*33338*333338+3333338*33333338+333333338
Sample Output 2
527930018
update @ 2024/3/10 01:30:32