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.