014. Labyrinth

Codeforces
IDCF10269014
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You find yourself stuck in a labyrinth and don't know your way out! There are several dangerous traps placed throughout the labyrinth. You need to find a way out, but first you need to know how many traps there are in the labyrinth. You will be 2D grid with dimensions _n_ by _m_. _x_ denotes a trap, and _._ denotes no trap. The first line of input will contain two space-separated integers _n_ and _m_, representing the dimensions of the grid. The next _n_ lines will each contain _m_ characters representing a row of the labyrinth. Output a single integer _t_: the total number of traps in the labyrinth. Hint: use a 2D array! ## Input You will be 2D grid with dimensions _n_ by _m_. _x_ denotes a trap, and _._ denotes no trap. The first line of input will contain two space-separated integers _n_ and _m_, representing the dimensions of the grid. The next _n_ lines will each contain _m_ characters representing a row of the labyrinth. ## Output Output a single integer _t_: the total number of traps in the labyrinth. [samples] ## Note Hint: use a 2D array!
**Definitions** Let $ n, m \in \mathbb{Z}^+ $ denote the dimensions of a 2D grid. Let $ G \in \{ \text{`x'}, \text{`.'} \}^{n \times m} $ be the grid representation, where `x` denotes a trap and `.` denotes no trap. **Constraints** 1. $ n \geq 1 $, $ m \geq 1 $ 2. Each cell $ G[i][j] \in \{ \text{`x'}, \text{`.'} \} $ for $ i \in \{1, \dots, n\} $, $ j \in \{1, \dots, m\} $ **Objective** Compute the total number of traps: $$ t = \sum_{i=1}^{n} \sum_{j=1}^{m} \mathbb{I}[G[i][j] = \text{`x'}] $$ where $ \mathbb{I}[\cdot] $ is the indicator function.
API Response (JSON)
{
  "problem": {
    "name": "014. Labyrinth",
    "description": {
      "content": "You find yourself stuck in a labyrinth and don't know your way out! There are several dangerous traps placed throughout the labyrinth. You need to find a way out, but first you need to know how many t",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269014"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You find yourself stuck in a labyrinth and don't know your way out! There are several dangerous traps placed throughout the labyrinth. You need to find a way out, but first you need to know how many t...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ denote the dimensions of a 2D grid.  \nLet $ G \\in \\{ \\text{`x'}, \\text{`.'} \\}^{n \\times m} $ be the grid representation, where `x` denotes a trap and `...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments