#P6343. Rectangular Empire Partition

    ID: 19559 Type: Default 1000ms 256MiB

Rectangular Empire Partition

Rectangular Empire Partition

A long time ago, the Rectangular Empire ruled over the Cartesian continent. The empire expanded its territory by conquering neighboring lands. It adopted a rectangular region system with the following conditions:

  • The empire’s territory is partitioned into regions, and every unit of land belongs to exactly one region.
  • Each region is a rectangle whose longer side is exactly twice its shorter side. In other words, if a region has side lengths a and b with a ≤ b (in units of \(\Xi\)), then it must satisfy \(b = 2a\).
  • The lengths of all sides are positive integers (in units of \(\Xi\)).

The empire started as a single region, but as it expanded by conquests it added new regions. Each time a new area is conquered, it is partitioned as a new region covering the entire newly acquired territory – without modifying any pre‐existing region or merging regions. The only requirement is that the overall shape of the empire remains a rectangle (its aspect ratio is not required to be \(2:1\)).

You are given the overall dimensions of the empire, \(n\) and \(m\) (in units of \(\Xi\)). Your task is to determine, among all possible valid partitions of the \(n \times m\) empire, the minimum and maximum possible numbers of regions. If the area \(n \times m\) is odd (and thus cannot be partitioned into regions of even area \(2a^2\)), output -1 -1.

Note: A rectangle of dimensions \(n\) and \(m\) is a valid region if and only if \(\max(n, m) = 2 \times \min(n, m)\). For instance, a region of size \(1 \times 2\) or \(2 \times 4\) (with area \(2\) and \(8\) respectively) is valid. Moreover, tiling the empire entirely with the smallest valid regions (i.e. dominoes of size \(1 \times 2\)) yields the maximum number of regions.

Input/Output Format: See details below.

inputFormat

The input consists of two space‐separated integers (n) and (m) representing the dimensions of the empire (in units of (\Xi)). It is guaranteed that (n, m \ge 1).

outputFormat

Output two integers separated by a space: the minimum and maximum number of regions into which the empire can be partitioned under the given rules. If no valid partition exists (i.e. if (n \times m) is odd), output -1 -1.

sample

1 2
1 1