Grid Construction

AtCoder
IDttpc2024_1_j
Time2000ms
Memory256MB
Difficulty
You are given positive integers $H$ and $W$. You aim to draw an $H$\-row by $W$\-column grid on the coordinate plane using several "U-shapes." To draw one U-shape, perform the following operation: * Choose integers $1 \le x \le H$ and $1 \le y \le W$. * From the following four line segments, select any three distinct ones: * The line segment connecting $(x-1, y-1)$ and $(x-1, y)$ * The line segment connecting $(x-1, y-1)$ and $(x, y-1)$ * The line segment connecting $(x, y)$ and $(x-1, y)$ * The line segment connecting $(x, y)$ and $(x, y-1)$ * Draw the selected three line segments on the coordinate plane. However, the line segments you draw must not share any points (other than endpoints) with any line segments drawn previously. Is it possible to draw all the length-$1$ line segments connecting grid points with $0 \le x \le H$ and $0 \le y \le W$ by repeating this operation? If possible, provide an example. ## Constraints * All input values are integers. * $1 \le H, W \le 1000$ ## Input The input is given from Standard Input in the following format: $H$ $W$ ## Partial Score $10$ points will be awarded for passing the testset satisfying the additional constraint $H,W\le 5$. [samples]
Samples
Input #1
3 3
Output #1
Yes
<<^
v.^
v>>

As shown in the figure, you can draw a $3 \times 3$ grid by drawing U-shapes. Note that no U-shape is drawn at the location corresponding to the center cell. (For clarity, the U-shapes are colored, but this is irrelevant to the problem.)
![image](https://img.atcoder.jp/ttpc2024_1/5c8124eb7c9068ad7af0603c6077344b.svg)
Input #2
4 4
Output #2
No
Input #3
4 5
Output #3
No
API Response (JSON)
{
  "problem": {
    "name": "Grid Construction",
    "description": {
      "content": "You are given positive integers $H$ and $W$. You aim to draw an $H$\\-row by $W$\\-column grid on the coordinate plane using several \"U-shapes.\" To draw one U-shape, perform the following operation: * ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "ttpc2024_1_j"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given positive integers $H$ and $W$. You aim to draw an $H$\\-row by $W$\\-column grid on the coordinate plane using several \"U-shapes.\"\nTo draw one U-shape, perform the following operation:\n\n* ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments