Packing snack sticks
Time limit2sMemory limit512 MB
Given n and m, decide whether an n by m grid can be tiled exactly with 3-cell straight bars and L trominoes that may be rotated.
- Level
Medium4 of 10
- Topics
- Math, Greedy, Implementation, Combinatorics
- Solved
- No attempts yet
Problem
Donghyuk has a part time job packing snack sticks. There are two kinds of snack. One is a rectangle, and the other is an L shape left when one cell is removed from a square. Both kinds cover exactly three cells.

A packing box is a grid of size . The snacks break easily: if any gap is left in the box, they rattle and crack. The box therefore has to be filled completely. You may rotate a snack and you may use as many snacks of each kind as you want, but snacks must not overlap and must not stick out of the box. The picture below shows a box filled with no gaps.

Given and , decide whether the box can be filled with no gaps.
Input
The first line contains the two side lengths and of the box, separated by a space. ()
Output
Print YES if the snacks can fill the box with no gaps, and NO otherwise.