QOJ.ac

QOJ

時間限制: 5 s 記憶體限制: 2048 MB 總分: 100

#7917. 木鞋舞

统计

在传统的荷兰木鞋舞中,舞者需要遵循一套非常具体的动作序列。舞蹈在一个正方形的网格上进行,舞蹈开始时,你站在网格左上角的方格上。你可以交替进行两种类型的舞步,并根据需要移动任意多次。你的第一步可以是任意一种舞步,但在此之后,你必须严格交替进行这两种舞步。

这两种舞步类似于国际象棋中的马步:在第一种舞步中,你从当前方格移动到沿网格一个轴方向移动 $a$ 个方格、沿另一个轴方向移动 $b$ 个方格的方格。同样,在第二种舞步中,你需要沿相应轴分别移动 $c$ 和 $d$ 个方格。由于你可以自由交换两个轴并选择每个轴上的移动方向,因此给定类型的舞步最多有 8 种执行方式。图 K.1 展示了一个 $(a, b) = (1, 2)$ 且 $(c, d) = (2, 3)$ 的舞蹈示例。

图 K.1:样例输入 3 的示意图,展示了从 4 × 4 网格的左上角开始,最终到达左下角的舞蹈过程,途中访问了蓝色方格。总共有 13 个可到达的方格。图中高亮显示的三个红色方格不能成为任何舞蹈表演的一部分。

从左上角的方格开始,在跳木鞋舞时你能到达多少个不同的方格?不允许走出网格,且在移动过程中跳过的方格不计入在内。注意,你需要统计的是在某些舞蹈表演过程中可以到达的所有方格,而不必是在同一次表演中到达的。

输入格式

输入包含: 一行一个整数 $n$ ($3 \le n \le 500$),表示正方形的边长。 一行两个整数 $a$ 和 $b$ ($1 \le a, b < n$),描述第一种舞步。 * 一行两个整数 $c$ 和 $d$ ($1 \le c, d < n$),描述第二种舞步。

输出格式

输出使用这些舞步可以到达的方格数量。

样例

样例输入 1

3
2 1
2 2

样例输出 1

6

样例输入 2

8
1 2
1 2

样例输出 2

64

样例输入 3

4
1 2
2 3

样例输出 3

13

样例输入 4

5
1 2
2 3

样例输出 4

25

样例输入 5

10
3 3
4 4

样例输出 5

50

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.