J. Jaber The policeman

Codeforces
IDCF10241J
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Jaber is a policeman of a city that can be described by a grid of size $n times m$, where every cell in that grid contains a house of one of the civilians. At night every person in the city should go sleep and should turn the lights of their house off. As a policeman Jaber should check the lights of every house in that city. Jaber checks every row and every column in that city exactly once, in the order written on a paper with Jaber. Every time Jaber checks a row or a column, he counts the number of houses that has their lights turned on. If he found more than one house with lights turned on he becomes sad. Also every time he checks a row or a column, he makes sure that every house in that row or column will turn off their lights. Ayoub doesn't remember exactly the description of the city, but he remembers in every row the number of houses that will have their lights on. Ayoub wants to know if it is possible to have a city with that description and has at least one correct order. The first line contains two integers $n$ and $m$ $(1 <= n, m <= 1000)$. The second line contains $n$ integers, the $i_{t h}$ one is $a_i$ $(0 <= a_i <= m)$, which is the number of houses that will have their lights on in the $i_{t h}$ row. If there is no possible answer print _NO_ on a line, otherwise print _YES_. if there is an answer you should print $n$ lines, the $i_{t h}$ line should contain $m$ characters, the $j_{t h}$ character should be _1_ if the house in the $i_{t h}$ row $j_{t h}$ column has their lights on, and _0_ otherwise. make sure that the number of _1_'s in the $i_{t h}$ row is equal to $a_i$. then you should print $n + m$ lines, which is a correct order of rows and columns that won't make Jaber sad. in every line you should print _row_ $x$ or _col_ $x$. make sure that every row and column appears exactly once. ## Input The first line contains two integers $n$ and $m$ $(1 <= n, m <= 1000)$.The second line contains $n$ integers, the $i_{t h}$ one is $a_i$ $(0 <= a_i <= m)$, which is the number of houses that will have their lights on in the $i_{t h}$ row. ## Output If there is no possible answer print _NO_ on a line, otherwise print _YES_.if there is an answer you should print $n$ lines, the $i_(t h)$ line should contain $m$ characters, the $j_(t h)$ character should be _1_ if the house in the $i_(t h)$ row $j_(t h)$ column has their lights on, and _0_ otherwise.make sure that the number of _1_'s in the $i_(t h)$ row is equal to $a_i$.then you should print $n + m$ lines, which is a correct order of rows and columns that won't make Jaber sad.in every line you should print _row_ $x$ or _col_ $x$.make sure that every row and column appears exactly once. [samples]
**Definitions** Let $ n, m \in \mathbb{Z}^+ $ be the dimensions of the grid. Let $ \mathbf{a} = (a_1, a_2, \dots, a_n) \in \mathbb{Z}_{\geq 0}^n $, where $ 0 \leq a_i \leq m $, denote the number of lights turned on in row $ i $. Let $ G \in \{0,1\}^{n \times m} $ be a binary matrix where $ G_{i,j} = 1 $ iff the light at row $ i $, column $ j $ is on. Let $ \mathcal{O} $ be a sequence of $ n + m $ operations, each being either _row $ i $| or _col $ j $|, such that each row and each column appears exactly once. **Constraints** 1. For each row $ i \in \{1, \dots, n\} $: $ \sum_{j=1}^m G_{i,j} = a_i $. 2. For each column $ j \in \{1, \dots, m\} $: $ \sum_{i=1}^n G_{i,j} = b_j $ for some $ \mathbf{b} \in \mathbb{Z}_{\geq 0}^m $ (to be determined). 3. There exists an order $ \mathcal{O} $ such that when processing operations sequentially: - Upon processing a row $ i $, the number of 1s in row $ i $ at that moment is $ \leq 1 $. - Upon processing a column $ j $, the number of 1s in column $ j $ at that moment is $ \leq 1 $. - After processing any row or column, all entries in it are set to 0. **Objective** Determine whether such a matrix $ G $ and order $ \mathcal{O} $ exist. If yes, output $ G $ and $ \mathcal{O} $. Otherwise, output "NO".
API Response (JSON)
{
  "problem": {
    "name": "J. Jaber The policeman",
    "description": {
      "content": "Jaber is a policeman of a city that can be described by a grid of size $n times m$, where every cell in that grid contains a house of one of the civilians. At night every person in the city should go",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10241J"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Jaber is a policeman of a city that can be described by a grid of size $n times m$, where every cell in that grid contains a house of one of the civilians.\n\nAt night every person in the city should go...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ be the dimensions of the grid.  \nLet $ \\mathbf{a} = (a_1, a_2, \\dots, a_n) \\in \\mathbb{Z}_{\\geq 0}^n $, where $ 0 \\leq a_i \\leq m $, denote the number o...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments