QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 10

#10251. 平滑排列 [A]

统计

我们将序列 $p_1, p_2, \dots, p_k$ 称为: 递增的,如果 $p_1 < p_2 < \dots < p_k$; 递减的,如果 $p_1 > p_2 > \dots > p_k$; * 凸的,如果存在某个 $1 \le l \le k$,使得序列 $p_1, p_2, \dots, p_l$ 是递增的,且序列 $p_l, p_{l+1}, \dots, p_k$ 是递减的。

特别地,单元素序列既被认为是递增的,也被认为是递减的和凸的。

如果一个排列同时满足以下三个条件,则称其为 $(a, b, c)$-平滑的: 其最长递增子序列的长度为 $a$; 其最长递减子序列的长度为 $b$; * 其最长凸子序列的长度为 $c$。

例如,排列 $4, 5, 2, 3, 1$ 是 $(2, 3, 4)$-平滑的,因为: 其最长递增子序列例如为 $4, 5$; 其最长递减子序列例如为 $4, 2, 1$; * 其最长凸子序列例如为 $4, 5, 3, 1$。

给定三个整数 $a, b, c$,满足 $1 \le a \le b \le c < a + b$,以及一个质数 $p$。可以证明,对于这样的三元组 $a, b, c$,所有 $(a, b, c)$-平滑排列的集合是非空且有限的。

编写一个程序,确定: 最长的 $(a, b, c)$-平滑排列的长度(记为 $n$); 长度为 $n$ 的 $(a, b, c)$-平滑排列的数量对 $p$ 取模的结果。

输入格式

输入仅一行,包含四个整数 $a, b, c, p$ ($1 \le a \le 20, a \le b \le 50\,000, b \le c < a + b, 10^7 \le p \le 10^9$),分别表示所考虑排列中递增子序列、递减子序列和凸子序列的最大长度,以及质数 $p$。

输出格式

输出仅一行,包含两个整数:最长的 $(a, b, c)$-平滑排列的长度,以及该长度下 $(a, b, c)$-平滑排列的数量对 $p$ 取模的结果。

样例

样例输入 1

2 2 3 10000019

样例输出 1

4 4

样例输入 2

2 3 3 999999937

样例输出 2

5 10

样例输入 3

8 9 11 15872567

样例输出 3

57 57

说明

样例说明:所有 $(2, 2, 3)$-平滑排列的集合如下: $1, 3, 2 \quad 2, 3, 1 \quad 2, 1, 4, 3 \quad 2, 4, 1, 3 \quad 3, 1, 4, 2 \quad 3, 4, 1, 2$ 其中最长的 4 个排列长度为 4。

在第二个样例中,我们考虑长度为 5 的 $(2, 3, 3)$-平滑排列: $3, 2, 1, 5, 4 \quad 3, 2, 5, 1, 4 \quad 4, 2, 1, 5, 3 \quad 4, 2, 5, 1, 3 \quad 4, 3, 1, 5, 2$ $4, 3, 5, 1, 2 \quad 5, 2, 1, 4, 3 \quad 5, 2, 4, 1, 3 \quad 5, 3, 1, 4, 2 \quad 5, 3, 4, 1, 2$

子任务

在分值非零的测试点中,满足条件 $c = a + b - 1$。

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.