G. Strings

Codeforces
IDCF10246G
Time4000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Once Gustave is happy with the final string he gets, he contacts a company to have the string printed on a strip of fabric. Being meticulous, Gustave does not want the company to make a single mistake. He thus computes a checksum out of his string and has the company do the same computation as a verification. The input consists of the following lines: *Limits* The output should consist of a single line, whose content is an integer, the sum of all ASCII codes of the characters of the final string $S (N -1)$ , modulo $1000000007$. ## Input The input consists of the following lines: The first line contains an integer $N$. The next line contains a string $S (0)$ of lowercase alphabetic characters between 'a' and 'z'. The next $N -1$ lines contain instructions to build strings $S (1), \\dots, S (N -1)$ . The instruction to build string $S (i)$ is either: "SUB $x$ $l o$ $h i$" with $x$, $l o$, $h i$ integers such that $0 <= x < i$ and $0 <= l o <= h i <= l e n g t h (S (x)$), or "APP $x$ $y$" with $x$, $y$ integers such that $0 <= x, y < i$. Instruction "SUB $x$ $l o$ $h i$" means that $S (i)$ is formed using (a copy of) characters of $S (x)$ from index $l o$ (inclusive) to $h i$ (exclusive). Characters are numbered starting from 0. Instruction "APP $x$ $y$" means that $S (i)$ is formed by concatenating copies of strings $S (x)$ and $S (y)$ in that order, i.e., with $S (x)$ coming first then $S (y)$ . *Limits* $1 <= N <= 2500$; $1 <= l e n g t h (S (0)) <= 1000$; the length of any string $S (i)$ will never exceed $2^(63) -1$. ## Output The output should consist of a single line, whose content is an integer, the sum of all ASCII codes of the characters of the final string $S (N -1)$ , modulo $1000000007$. [samples]
**Definitions** Let $ S $ be the final string. **Objective** Compute: $$ \left( \sum_{c \in S} \text{ASCII}(c) \right) \bmod 1000000007 $$
API Response (JSON)
{
  "problem": {
    "name": "G. Strings",
    "description": {
      "content": "Once Gustave is happy with the final string he gets, he contacts a company to have the string printed on a strip of fabric. Being meticulous, Gustave does not want the company to make a single mistake",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10246G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Once Gustave is happy with the final string he gets, he contacts a company to have the string printed on a strip of fabric. Being meticulous, Gustave does not want the company to make a single mistake...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ S $ be the final string.  \n\n**Objective**  \nCompute:  \n$$\n\\left( \\sum_{c \\in S} \\text{ASCII}(c) \\right) \\bmod 1000000007\n$$...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments