#abc219e. E - Moat

E - Moat

Score : 500500 points

问题描述

xyxy 平面上有一些点,代表了一些村庄的位置。
高桥将要构建一条护城河来保护这些村庄免受敌人的侵袭,比如民间军队和女巫。

你得到一个由 0011 组成的 4×44 \times 4 矩阵 A=(Ai,j)A = (A_{i, j})
对于每一对整数 (i,j)(i, j) 满足 1i,j41 \leq i, j \leq 4Ai,j=1A_{i, j} = 1,坐标 (i0.5,j0.5)(i-0.5, j-0.5) 处就有一个村庄。

护城河将在平面上形成一个多边形。高桥将按照以下条件来建造它。(参见示例输入/输出 1 的注释部分。)

  1. 没有自相交。
  2. 所有村庄都在多边形内部。
  3. 每个顶点的 xxyy 坐标都是整数,范围在 0044(包含)之间。
  4. 每条边都与 xx 轴或 yy 轴平行。
  5. 每个内角为 9090 度或 270270 度。

请输出高桥构建护城河的不同方法数量。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are villages at some number of points in the xyxy-plane.
Takahashi will construct a moat to protect these villages from enemies such as civil armies and witches.

You are given a 4×44 \times 4 matrix A=(Ai,j)A = (A_{i, j}) consisting of 00 and 11.
For each pair of integers (i,j)(i, j) (1i,j4)(1 \leq i, j \leq 4) such that Ai,j=1A_{i, j} = 1, there is a village at the coordinates (i0.5,j0.5)(i-0.5, j-0.5).

The moat will be a polygon in the plane. Takahashi will construct it so that the following conditions will be satisfied. (See also the annotation at Sample Input/Output 1.)

  1. There is no self-intersection.
  2. All villages are contained in the interior of the polygon.
  3. The xx- and yy-coordinates of every vertex are integers between 00 and 44 (inclusive).
  4. Every edge is parallel to the xx- or yy-axis.
  5. Every inner angle is 9090 or 270270 degrees.

Print the number of ways in which Takahashi can construct the moat.

Constraints

  • Ai,j{0,1}A_{i, j} \in \lbrace 0, 1\rbrace
  • There is at least one pair (i,j)(i, j) such that Ai,j=1A_{i, j} = 1.

Input

Input is given from Standard Input in the following format:

A1,1A_{1, 1} A1,2A_{1, 2} A1,3A_{1, 3} A1,4A_{1, 4}

A2,1A_{2, 1} A2,2A_{2, 2} A2,3A_{2, 3} A2,4A_{2, 4}

A3,1A_{3, 1} A3,2A_{3, 2} A3,3A_{3, 3} A3,4A_{3, 4}

A4,1A_{4, 1} A4,2A_{4, 2} A4,3A_{4, 3} A4,4A_{4, 4}

Output

Print the number of ways in which Takahashi can construct the moat.

Sample Input 1

1 0 0 0
0 0 1 0
0 0 0 0
1 0 0 0

Sample Output 1

1272

The two ways to construct the moat shown in the images below are valid.

The four ways to construct the moat shown in the images below are invalid.

Here are the reasons the above ways are invalid.

  • The first way violates the condition: "There is no self-intersection."
  • The second way violates the condition: "All villages are contained in the interior of the polygon."
  • The third way violates the condition: "The xx- and yy-coordinates of every vertex are integers between 00 and 44." (Some vertices have non-integer coordinates.)
  • The fourth way violates the condition: "Every edge is parallel to the xx- or yy-axis."

Sample Input 2

1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1

Sample Output 2

1

update @ 2024/3/10 09:41:56

}