QOJ.ac

QOJ

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

#977. 極大値

統計

$n \times m$ の整数行列 $A$ において、$A$ の局所最大値(local maximum)とは、位置 $(i, j)$ ($1 \le i \le n$ かつ $1 \le j \le m$) であって、$A_{i,j}$ が $i$ 行目または $j$ 列目の他のどの整数よりも小さくないものを指します。

例えば、$3 \times 3$ 行列 $$ \begin{bmatrix} 2 & 5 & 4 \\ 2 & 1 & 6 \\ 2 & 2 & 2 \end{bmatrix} $$ において、局所最大値は 3 つ存在します。位置 $(1, 2)$、$(2, 3)$、$(3, 1)$ で、値はそれぞれ 5、6、2 です。

$n \times m$ の整数行列 $A$ が「良い(good)」とは、以下の 2 つの条件を両方満たすことを指します。

  • $A$ に局所最大値がちょうど 1 つ存在する。
  • $1$ から $n \times m$ までの各整数が $A$ にちょうど 1 回ずつ現れる。

$n, m$ および素数 $P$ が与えられます。サイズ $n \times m$ の良い行列の個数を $P$ を法として求めてください。

入力

入力の最初の行には 3 つの整数 $n, m, P$ が含まれます。ここで $1 \le n, m \le 3000$ かつ $10^8 \le P \le 10^9 + 7$ です。$P$ は素数であることが保証されています。

出力

良い行列の個数を $P$ を法として 1 行で出力してください。

入出力例

入力 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.