QOJ.ac

QOJ

実行時間制限: 4 s メモリ制限: 512 MB 満点: 100

#977. 局部极大值

統計

给定一个 $n \times m$ 的整数矩阵 $A$,如果位置 $(i, j)$ ($1 \le i \le n$ 且 $1 \le j \le m$) 满足 $A_{i,j}$ 不小于第 $i$ 行或第 $j$ 列中的任何其他整数,则称该位置为 $A$ 的一个局部最大值(local maximum)。

例如,在 $3 \times 3$ 矩阵 $$\begin{bmatrix} 2 & 5 & 4 \\ 2 & 1 & 6 \\ 2 & 2 & 2 \end{bmatrix}$$ 中,有三个局部最大值:位置 $(1, 2)$、$(2, 3)$ 和 $(3, 1)$,其值分别为 $5$、$6$ 和 $2$。

一个 $n \times m$ 的整数矩阵 $A$ 是“好的”(good),当且仅当它满足以下两个条件: $A$ 中恰好有一个局部最大值。 从 $1$ 到 $n \times m$ 的每个整数在 $A$ 中恰好出现一次。

给定 $n$、$m$ 和一个素数 $P$,你的任务是计算大小为 $n \times m$ 的“好的”矩阵的数量,结果对 $P$ 取模。

输入格式

第一行包含三个整数 $n$、$m$ 和 $P$,其中 $1 \le n, m \le 3000$ 且 $10^8 \le P \le 10^9 + 7$。保证 $P$ 是素数。

输出格式

输出一行,包含一个整数:满足条件的“好的”矩阵的数量对 $P$ 取模的结果。

样例

输入 1

2 2 1000000007

输出 1

16

输入 2

4 3 1000000007

输出 2

95800320

输入 3

100 100 998244353

输出 3

848530760

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#517Editorial Open集训队作业 解题报告 by 全柏锋Qingyu2026-01-02 21:36:43 Download

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.