M. Variable Shadowing

Codeforces
IDCF10051M
Time2000ms
Memory512MB
Difficulty
English · Original
Formal · Original
In computer programming, _variable shadowing_ occurs when a variable declared within a certain scope has the same name as a variable declared in an outer scope. The outer variable is said to be shadowed by the inner variable, and this can lead to confusion. If multiple outer scopes contain variables with the same name, the variable in the nearest scope will be shadowed. Formally, declared variable shadows another declared variable if the following conditions are met simultaneously: Here is an example containing exactly one variable shadowing: Variable shadowing is permitted in many modern programming languages including C++, but compilers can warn a programmer about variable shadowing to avoid possible mistakes in a code. Consider a trivial programming language that consists only of scopes and variable declarations. The program consists of lines, each line contains only characters '_{_', '_}_', '_a_' ... '_z_' separated by one or more spaces. Given a syntactically correct program (i.e. curly brackets form a _regular bracket sequence_), write an analyzer to warn about each fact of variable shadowing. Warnings should include exact positions of shadowing and shadowed variables. Your output should follow the format shown in the examples below. The first line contains integer n (1 ≤ n ≤ 50) — the number of lines in the program. The following n lines contain the program. Each program line consists of tokens '_{_', '_}_', '_a_' ... '_z_' separated by one or more spaces. The length of each line is between 1 and 50 characters. Each program line contains at least one non-space character. The curly brackets in the program form a _regular bracket sequence_, so each opening bracket '_{_' has uniquely defined matching closing bracket '_}_' and vice versa. A variable is declared in scope at most once. Any scope (including global) can be empty, i.e. can contain no variable declarations. For each fact of shadowing write a line in the form "_r1:c1: warning: shadowed declaration of ?, the shadowed position is r2:c2_", where "_r1:c1_" is the number of line and position in the line of shadowing declaration and "_r2:c2_" is the number of line and position in the line of shadowed declaration. Replace '_?_' with the letter _'a' ... 'z'_ — the name of shadowing/shadowed variable. If multiple outer scopes have variables named as the shadowing variable, the variable in the nearest outer scope is shadowed. Print warnings in increasing order of _r1_, or in increasing order of _c1_ if values _r1_ are equal. Leave the output empty if there are no variable shadowings. ## Input The first line contains integer n (1 ≤ n ≤ 50) — the number of lines in the program. The following n lines contain the program. Each program line consists of tokens '_{_', '_}_', '_a_' ... '_z_' separated by one or more spaces. The length of each line is between 1 and 50 characters. Each program line contains at least one non-space character.The curly brackets in the program form a _regular bracket sequence_, so each opening bracket '_{_' has uniquely defined matching closing bracket '_}_' and vice versa. A variable is declared in scope at most once. Any scope (including global) can be empty, i.e. can contain no variable declarations. ## Output For each fact of shadowing write a line in the form "_r1:c1: warning: shadowed declaration of ?, the shadowed position is r2:c2_", where "_r1:c1_" is the number of line and position in the line of shadowing declaration and "_r2:c2_" is the number of line and position in the line of shadowed declaration. Replace '_?_' with the letter _'a' ... 'z'_ — the name of shadowing/shadowed variable. If multiple outer scopes have variables named as the shadowing variable, the variable in the nearest outer scope is shadowed.Print warnings in increasing order of _r1_, or in increasing order of _c1_ if values _r1_ are equal. Leave the output empty if there are no variable shadowings. [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be the length of the encrypted string. Let $ E = (e_1, e_2, \dots, e_n) $ be the sequence of ASCII codes of the encrypted string, where $ e_i \in \{0, 1, \dots, 255\} $ for all $ i \in \{1, \dots, n\} $. **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. $ 0 \leq e_i \leq 255 $ for all $ i \in \{1, \dots, n\} $ 3. The original string consists only of lowercase English letters (ASCII codes 97 to 122). **Objective** Recover the original string $ S = (s_1, s_2, \dots, s_n) $, where each $ s_i $ is the character corresponding to ASCII code $ e_i $, i.e., $$ s_i = \text{chr}(e_i) $$ and output the concatenated string $ s_1 s_2 \dots s_n $.
API Response (JSON)
{
  "problem": {
    "name": "M. Variable Shadowing",
    "description": {
      "content": "In computer programming, _variable shadowing_ occurs when a variable declared within a certain scope has the same name as a variable declared in an outer scope. The outer variable is said to be shadow",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10051M"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "In computer programming, _variable shadowing_ occurs when a variable declared within a certain scope has the same name as a variable declared in an outer scope. The outer variable is said to be shadow...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the length of the encrypted string.  \nLet $ E = (e_1, e_2, \\dots, e_n) $ be the sequence of ASCII codes of the encrypted string, where $ e_i \\in \\{0, 1, \\...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments