101. Metropolis

Codeforces
IDCF10269101
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Metropolis You're driving through a metropolis. The metropolis can be represented as a 2D grid of buildings, each with a height value between $0$ and $9$. You consider a building to be a _skyscraper_ if it has a greater height than all of the buildings directly adjacent to it (including diagonally). Given this 2D grid of building heights, figure out which buildings are skyscrapers, and which ones aren't. The first line of input contains a positive integer $n$: the height and width of the metropolis. The height and width are always equal, so the metropolis is always a square. The next $n$ lines each contain strings of $n$ characters, each character being a digit from $0$ to $9$ representing the height of each building. Output $n$ lines. Each line should consist of a string of $n$ characters, with each character being $Y$, if the building at that position is a skyscraper, and $N$ if it is not. ## Input The first line of input contains a positive integer $n$: the height and width of the metropolis. The height and width are always equal, so the metropolis is always a square. The next $n$ lines each contain strings of $n$ characters, each character being a digit from $0$ to $9$ representing the height of each building. ## Output Output $n$ lines. Each line should consist of a string of $n$ characters, with each character being $Y$, if the building at that position is a skyscraper, and $N$ if it is not. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the side length of the square grid. Let $ H = (h_{i,j})_{i,j=1}^n $ be the grid of building heights, where $ h_{i,j} \in \{0,1,\dots,9\} $ for all $ i,j \in \{1,\dots,n\} $. **Constraints** 1. $ 1 \leq n \leq \text{some upper bound (implied by input)} $ 2. $ h_{i,j} \in \{0,1,\dots,9\} $ for all $ i,j \in \{1,\dots,n\} $ **Objective** For each position $ (i,j) \in \{1,\dots,n\}^2 $, define the set of 8-neighbors: $$ N(i,j) = \left\{ (i',j') \in \{1,\dots,n\}^2 \setminus \{(i,j)\} \,\middle|\, |i - i'| \leq 1 \text{ and } |j - j'| \leq 1 \right\} $$ Then, define the output grid $ O = (o_{i,j})_{i,j=1}^n $, where: $$ o_{i,j} = \begin{cases} Y & \text{if } h_{i,j} > \max\{ h_{i',j'} \mid (i',j') \in N(i,j) \} \\ N & \text{otherwise} \end{cases} $$ Output the grid $ O $.
API Response (JSON)
{
  "problem": {
    "name": "101. Metropolis",
    "description": {
      "content": "Metropolis You're driving through a metropolis. The metropolis can be represented as a 2D grid of buildings, each with a height value between $0$ and $9$. You consider a building to be a _skyscraper_",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269101"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Metropolis\n\nYou're driving through a metropolis. The metropolis can be represented as a 2D grid of buildings, each with a height value between $0$ and $9$. You consider a building to be a _skyscraper_...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the side length of the square grid.  \nLet $ H = (h_{i,j})_{i,j=1}^n $ be the grid of building heights, where $ h_{i,j} \\in \\{0,1,\\dots,9\\} $ for all $ i...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments