Saturn Bees
Time limit2sMemory limit512 MB
On a torus-like hexagonal grid, decide whether nm/4 vertices can each dominate a closed neighborhood of 4 vertices, covering every vertex.
- Level
Hard8 of 10
- Topics
- Math, Combinatorics, Implementation, Brute force
- Solved
- No attempts yet
Problem
The Saturn bee (Apis saturnii) builds its hive in the shape of a ring. A beehive is a hexagonal grid, and we model it as a graph whose edges are walls and whose vertices are the joins between walls. Flatten every hexagon a little so that it becomes a rectangle. Then every vertex gets an integer coordinate, and vertex is adjacent to , to , and to when is odd or to when is even.
To turn an grid into a ring the edges wrap around. If and are both even, an edge with endpoint ends at instead, and an edge with endpoint ends at . If one of the two numbers is odd, the bees twist the grid so that both sides match: if is odd then becomes , and if is odd then becomes . The swarm mind knows the handshaking lemma and never builds a beehive in which and are both odd. Figure A.1 shows a few beehives.

Figure A.1: Example beehives
Each soldier bee sits on a vertex and controls that vertex together with the 3 vertices adjacent to it. The swarm mind knows that bees are needed to control the whole hive, so the swarm carries exactly that many soldiers. Some beehives turn out to be hard to guard, and the Saturn bees refuse to live there.
Decide whether a beehive is a suitable home for a swarm.
Input
The first line contains two integers and (). At least one of and is even.
Output
Print possible if bees can guard an beehive, and impossible otherwise. If is not divisible by 4 the swarm cannot be assembled, so print impossible.