QOJ.ac

QOJ

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

#17430. 唯一纸片

Statistics

有一个 $N \times N$ 的网格,其中每个单元格 $(i, j)$ 包含一个整数 $A_{i,j}$ ($1 \le A_{i,j} \le (N - K)^2$)。熊猫 Pataro 在该网格上进行了以下操作:

  • 从 $N$ 行中选择 $K$ 行并将其删除。
  • 从 $N$ 列中选择 $K$ 列并将其删除。

在执行这些操作后,网格中所有剩余的 $(N - K)^2$ 个整数互不相同。 求 Pataro 执行这些操作的可能方案数,模 $998244353$。

两种操作方案被认为是不同的,当且仅当选择的行集合或选择的列集合不同。

输入格式

输入按以下格式给出:

N K
A_{1,1} A_{1,2} ... A_{1,N}
:
A_{N,1} A_{N,2} ... A_{N,N}

输出格式

输出执行这些操作的方案数,模 $998244353$。

数据范围

  • $1 \le K < N \le 1000$
  • $1 \le K \le 5$
  • $1 \le A_{i,j} \le (N - K)^2$ ($1 \le i \le N, 1 \le j \le N$)
  • 所有输入值均为整数。

样例

输入 1

3 1
1 2 4
3 4 2
2 1 3

输出 1

6

输入 2

6 5
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1

输出 2

36

输入 3

7 5
2 3 1 4 1 3 1
4 4 1 4 1 1 1
1 3 4 1 4 3 4
4 2 2 2 1 2 2
2 4 1 4 2 3 1
2 3 1 3 1 2 4
3 3 2 1 4 2 2

输出 3

36

说明

在第一个样例中,有 $6$ 种满足条件的操作方案。对于每种方案,剩余的 $(N - K)^2$ 个整数从小到大排列恰好是 $1, 2, 3, 4$。

  • 在第一次操作中选择第 $1$ 行,在第二次操作中选择第 $1$ 列。
  • 在第一次操作中选择第 $1$ 行,在第二次操作中选择第 $3$ 列。
  • 在第一次操作中选择第 $2$ 行,在第二次操作中选择第 $1$ 列。
  • 在第一次操作中选择第 $2$ 行,在第二次操作中选择第 $2$ 列。
  • 在第一次操作中选择第 $3$ 行,在第二次操作中选择第 $2$ 列。
  • 在第一次操作中选择第 $3$ 行,在第二次操作中选择第 $3$ 列。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1494EditorialOpen题解jiangly2026-04-09 18:14:49View
#1346EditorialOpen题解Milmon2026-03-29 19:51:31View

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.