QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#16228. Sum of Three Inversions

Statistics

给你整数 $N, X, Y, K$ 和 $M$。求满足以下所有条件的长度为 $N$ 的整数序列三元组 $(A, B, C)$ 的数量,模 $M$ 的余数。

  • 对于每个 $i = 1, 2, \dots, N$,三元组 $(A_i, B_i, C_i)$ 是 $(1, 2, 3)$ 的一个排列。
  • 序列 $A$ 恰好包含 $X$ 个 $1$ 和 $Y$ 个 $2$。
  • $A, B$ 和 $C$ 的逆序对数之和等于 $K$。

这里,一个序列 $a$ 的逆序对数定义为满足 $1 \le i < j \le |a|$ 且 $a_i > a_j$ 的整数对 $(i, j)$ 的数量。

输入格式

输入格式如下:

N X Y K M

数据范围

  • 所有输入值均为整数。
  • $2 \le N \le 50$
  • $0 \le X, Y \le N$
  • $X + Y \le N$
  • $0 \le K \le \frac{3}{2}N(N - 1)$
  • $10^8 \le M \le 10^9$

输出格式

输出答案。

样例

输入样例 1

3 1 1 4 998244353

输出样例 1

24

输入样例 2

4 0 0 18 123456789

输出样例 2

0

输入样例 3

50 10 20 1000 1000000000

输出样例 3

805988728

说明

在第一个样例中,有 $24$ 个满足条件的三元组 $(A, B, C)$。例如,如果我们取 $A = (1, 2, 3)$,$B = (3, 3, 2)$,且 $C = (2, 1, 1)$,则 $(A, B, C)$ 满足所有条件。

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.