evall

AtCoder
IDabc338_g
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
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
API Response (JSON)
{
  "problem": {
    "name": "evall",
    "description": {
      "content": "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 integer",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc338_g"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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$.\nFor a pair of integer...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments