Tile Grid with One Hole

AtCoder
IDarc203_e
Time2000ms
Memory256MB
Difficulty
There is a grid with $H$ rows and $W$ columns, where the cell at the $i$\-th row from the top and $j$\-th column from the left is denoted as $(i,j)$. The grid has a hole only in cell $(r,c)$. We will tile all cells without a hole using several tiles. You are given non-negative integers $N$ and $M$ such that $H \times W=L \times (N+M)+1$. A tile of $1$ row and $L$ columns is called a horizontal tile, and a tile of $L$ rows and $1$ column is called a vertical tile. Determine whether there exists a way to tile using exactly $N$ horizontal tiles and $M$ vertical tiles without rotation, and also show one such way if it exists. For details on the output format and more precise conditions, check the output section. Solve $T$ test cases for each input file. ## Constraints * $1 \leq T \leq 5$ * $1 \leq H \leq 1000$ * $1 \leq W \leq 1000$ * $2 \leq H \times W$ * $2 \leq L \leq 1000$ * $0 \leq N$ * $0 \leq M$ * $1 \leq r \leq H$ * $1 \leq c \leq W$ * $H \times W=L \times (N+M)+1$ * The sum of $N+M$ over all test cases is at most $6\times 10^5$. * All input values are integers. ## Input The input is given from Standard Input in the following format: $T$ $case_1$ $case_2$ $\vdots$ $case_T$ Each case is given in the following format: $H$ $W$ $L$ $N$ $M$ $r$ $c$ [samples]
Samples
Input #1
3
1 3 2 1 0 1 1
1 3 2 1 0 1 2
3 3 2 1 3 1 1
Output #1
Yes
1 2
No
Yes
3 2
2 1
1 2
1 3

In the third test case, there is a hole in the top-left cell. It can be tiled as follows:

  ┌─┬─┐
┌─┤ │ │
│ ├─┴─┤
└─┴───┘
API Response (JSON)
{
  "problem": {
    "name": "Tile Grid with One Hole",
    "description": {
      "content": "There is a grid with $H$ rows and $W$ columns, where the cell at the $i$\\-th row from the top and $j$\\-th column from the left is denoted as $(i,j)$. The grid has a hole only in cell $(r,c)$. We will ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc203_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a grid with $H$ rows and $W$ columns, where the cell at the $i$\\-th row from the top and $j$\\-th column from the left is denoted as $(i,j)$. The grid has a hole only in cell $(r,c)$. We will ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments