Connection Status:
Competition Arena > PolyominoCut
SRM 242 · 2005-05-14 · by gepa · Graph Theory, Recursion, Simple Math
Class Name: PolyominoCut
Return Type: int
Method Name: count
Arg Types: (int, int, int)
Problem Statement

Problem Statement

You are given a rectangular board consisting of width times height small squares. Return the number of different ways there are to cut a k-polyomino out of this board, so that the remaining part remains connected.

A k-polyomino is a connected set of k squares. The figure below shows as an example all possible pentominoes (5-polyominoes) ignoring any translations, rotations or reflections.

Connected means side-connected here (both in the polyomino definition and in the requirement for the remaining part of the board) - i.e., you must be able to go from any square to any other by only going through squares and square-sides but not square-corners.

For two ways of cutting a polyomino out of the grid to be different and be counted separately it suffices if at least one grid square is included in the first polyomino but not in the other.

The example below shows some polyomino cuts for k=7. The two on the left (red) are not counted, since they leave the remaining grid disconnected, while the one on the right (green) is counted.

Constraints

  • k will be between 1 and 8, inclusive.
  • width and height will be between k+1 and 800, inclusive.
Examples
0)
1
10
20
Returns: 200

There is only one 1-polyomino (called monomino), and this can be cut out anywhere on the grid.

1)
3
10
10
Returns: 480

There are in total 484 ways to cut a triomino (3-polyomino) out of a 10x10 square, but 4 of them leave a square in the corner not connected (see figure below), so only 480 satisfy the problem requirements.

2)
8
800
800
Returns: 1704053350

The worst case fits in an int.

3)
8
780
778
Returns: 1615412228
4)
8
776
16
Returns: 26549726

Submissions are judged against all 65 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class PolyominoCut with a public method int count(int k, int width, int height) · 65 test cases · 2 s / 256 MB per case

Submitting as anonymous