QOJ.ac

QOJ

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

#977. 로컬 최댓값

統計

$n \times m$ 정수 행렬 $A$에서, $A$의 지역 최댓값(local maximum)이란 $A_{i,j}$가 $i$번째 행 또는 $j$번째 열에 있는 다른 어떤 정수보다 작지 않은 위치 $(i, j)$ ($1 \le i \le n$ 및 $1 \le j \le m$)를 의미합니다.

예를 들어, $3 \times 3$ 행렬 $$ \begin{bmatrix} 2 & 5 & 4 \\ 2 & 1 & 6 \\ 2 & 2 & 2 \end{bmatrix} $$ 에서, 지역 최댓값은 세 개가 존재합니다: 각각 값 5, 6, 2를 가지는 위치 (1, 2), (2, 3), (3, 1)입니다.

$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.