J. Mex Grid

Codeforces
IDCF10286J
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You are given two arrays of integers $a$ and $b$. The length of $a$ is $n$ and the length of $b$ is $m$. Your task is to find any matrix $C$ of size $n times m$, which satisfies all of the following properties: Mex stands for "minimum excluded": the mex of a set of numbers is equal to the smallest non-negative integer which is not present in the set. For example, $"mex"({0, 1, 2, 4}) = 3$. The first line contains two positive integers $n$ and $m$, the lengths of the arrays $a$ and $b$ ($1 <= n dot.op m <= 10^5$). The second line contains $n$ integers $a_1$, $\\dots$, $a_n$ ($0 <= a_i <= 10^9$). The third line contains $m$ integers $b_1$, $\\dots$, $b_m$ ($0 <= b_i <= 10^9$). If there exists such a matrix, output "_Yes_" in the first line. Otherwise, output "_No_". In the first case also output the required matrix. Output $n$ rows of $m$ integers, where the the $j$-th integer of the $i$-th row is $C_{i , j}$. Each integer from the interval $[ 0, n dot.op m -1 ]$ should appear exactly once in $C$. If there exist multiple such matrices, output any of those. ## Input The first line contains two positive integers $n$ and $m$, the lengths of the arrays $a$ and $b$ ($1 <= n dot.op m <= 10^5$). The second line contains $n$ integers $a_1$, $\\dots$, $a_n$ ($0 <= a_i <= 10^9$). The third line contains $m$ integers $b_1$, $\\dots$, $b_m$ ($0 <= b_i <= 10^9$). ## Output If there exists such a matrix, output "_Yes_" in the first line. Otherwise, output "_No_".In the first case also output the required matrix. Output $n$ rows of $m$ integers, where the the $j$-th integer of the $i$-th row is $C_(i comma j)$. Each integer from the interval $[ 0, n dot.op m -1 ]$ should appear exactly once in $C$. If there exist multiple such matrices, output any of those. [samples]
**Definitions** Let $ n, m \in \mathbb{Z}^+ $ with $ 1 \leq n \cdot m \leq 10^5 $. Let $ A = (a_1, \dots, a_n) \in \mathbb{Z}^n $, $ B = (b_1, \dots, b_m) \in \mathbb{Z}^m $. Let $ C \in \mathbb{Z}^{n \times m} $ be a matrix such that each integer in $ \{0, 1, \dots, nm - 1\} $ appears exactly once in $ C $. **Constraints** For all $ i \in \{1, \dots, n\} $, $ j \in \{1, \dots, m\} $: $$ \mathrm{mex}\left( \{ C_{i,k} \mid k = 1, \dots, m \} \right) = a_i $$ $$ \mathrm{mex}\left( \{ C_{k,j} \mid k = 1, \dots, n \} \right) = b_j $$ **Objective** Determine whether such a matrix $ C $ exists. If yes, output "Yes" and any such matrix; otherwise, output "No".
API Response (JSON)
{
  "problem": {
    "name": "J. Mex Grid",
    "description": {
      "content": "You are given two arrays of integers $a$ and $b$. The length of $a$ is $n$ and the length of $b$ is $m$. Your task is to find any matrix $C$ of size $n times m$, which satisfies all of the following p",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10286J"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given two arrays of integers $a$ and $b$. The length of $a$ is $n$ and the length of $b$ is $m$. Your task is to find any matrix $C$ of size $n times m$, which satisfies all of the following p...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ with $ 1 \\leq n \\cdot m \\leq 10^5 $.  \nLet $ A = (a_1, \\dots, a_n) \\in \\mathbb{Z}^n $, $ B = (b_1, \\dots, b_m) \\in \\mathbb{Z}^m $.  \nLet $ C \\in \\mathbb...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments