F. Long number

Codeforces
IDCF759F
Time2000ms
Memory512MB
Difficulty
math
English · Original
Chinese · Translation
Formal · Original
Consider the following grammar: * _<expression> ::= <term> | <expression> '+' <term>_ * _<term> ::= <number> | <number> '-' <number> | <number> '(' <expression> ')'_ * _<number> ::= <pos_digit> | <number> <digit>_ * _<digit> ::= '0' | <pos_digit>_ * _<pos_digit> ::= '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'_ This grammar describes a number in decimal system using the following rules: * _<number>_ describes itself, * _<number>-<number>_ (_l-r_, _l_ ≤ _r_) describes integer which is concatenation of all integers from _l_ to _r_, written without leading zeros. For example, _8-11_ describes _891011_, * _<number>(<expression>)_ describes integer which is concatenation of <number> copies of integer described by _<expression>_, * _<expression>+<term>_ describes integer which is concatenation of integers described by _<expression>_ and _<term>_. For example, _2(2-4+1)+2(2(17))_ describes the integer _2341234117171717_. You are given an expression in the given grammar. Print the integer described by it modulo 109 + 7. ## Input The only line contains a non-empty string at most 105 characters long which is valid according to the given grammar. In particular, it means that in terms _l-r_ _l_ ≤ _r_ holds. ## Output Print single integer — the number described by the expression modulo 109 + 7. [samples]
考虑以下文法: 该文法使用以下规则描述十进制系统中的数字: 例如,_2(2-4+1)+2(2(17))_ 描述整数 _2341234117171717_。 给定一个符合该文法的表达式,请输出其描述的整数对 #cf_span[109 + 7] 取模的结果。 输入仅有一行,包含一个非空字符串,长度不超过 #cf_span[105],且符合上述文法。特别地,这意味着在形如 _l-r_ 的项中,#cf_span[l ≤ r] 成立。 请输出一个整数——该表达式所描述的数对 #cf_span[109 + 7] 取模的结果。 ## Input 输入仅有一行,包含一个非空字符串,长度不超过 #cf_span[105],且符合上述文法。特别地,这意味着在形如 _l-r_ 的项中,#cf_span[l ≤ r] 成立。 ## Output 请输出一个整数——该表达式所描述的数对 #cf_span[109 + 7] 取模的结果。 [samples]
**Definitions** Let $ G $ be a grammar over alphabet $ \Sigma = \{0,1,\dots,9, +, -, (, )\} $, with recursive production rules: - A *term* is a digit $ d \in \{0,1,\dots,9\} $, or a compound expression of the form $ l - r $ or $ n(E) $, where: - $ l, r $ are terms with $ l \leq r $ (inclusive range), - $ n \in \mathbb{Z}_{\geq 1} $ is a positive integer (multiplier), - $ E $ is a term. The semantics of a term $ T $ is a string $ s(T) \in \{0,1,\dots,9\}^* $, defined recursively: - If $ T = d $, then $ s(T) = d $ (as a string). - If $ T = l - r $, then $ s(T) = \bigcup_{k=l}^{r} s(k) $, i.e., concatenation of strings $ s(l), s(l+1), \dots, s(r) $. - If $ T = n(E) $, then $ s(T) = s(E)^n $, i.e., $ s(E) $ repeated $ n $ times. Let $ N(T) $ be the integer value of the decimal string $ s(T) $, interpreted in base 10. **Constraints** - Input is a single string $ T $ of length $ \leq 10^5 $, valid under grammar $ G $. - All numeric literals in ranges $ l, r $ satisfy $ l \leq r $. **Objective** Compute $ N(T) \mod (10^9 + 7) $.
Samples
Input #1
8-11
Output #1
891011
Input #2
2(2-4+1)+2(2(17))
Output #2
100783079
Input #3
1234-5678
Output #3
745428774
Input #4
1+2+3+4-5+6+7-9
Output #4
123456789
API Response (JSON)
{
  "problem": {
    "name": "F. Long number",
    "description": {
      "content": "Consider the following grammar: *   _<expression> ::= <term> | <expression> '+' <term>_ *   _<term> ::= <number> | <number> '-' <number> | <number> '(' <expression> ')'_ *   _<number> ::= <pos_digit>",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF759F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Consider the following grammar:\n\n*   _<expression> ::= <term> | <expression> '+' <term>_\n*   _<term> ::= <number> | <number> '-' <number> | <number> '(' <expression> ')'_\n*   _<number> ::= <pos_digit>...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "考虑以下文法:\n\n该文法使用以下规则描述十进制系统中的数字:\n\n例如,_2(2-4+1)+2(2(17))_ 描述整数 _2341234117171717_。\n\n给定一个符合该文法的表达式,请输出其描述的整数对 #cf_span[109 + 7] 取模的结果。\n\n输入仅有一行,包含一个非空字符串,长度不超过 #cf_span[105],且符合上述文法。特别地,这意味着在形如 _l-r_ 的项中,#...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ G $ be a grammar over alphabet $ \\Sigma = \\{0,1,\\dots,9, +, -, (, )\\} $, with recursive production rules:  \n- A *term* is a digit $ d \\in \\{0,1,\\dots,9\\} $, or a compound expre...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments