Universal Cup Judging System

Universal Cup

时间限制: 3.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓
统计

問題文

$N \times N$ のマス目からなる正方形のグリッドがあります。上から $i$ 行目、左から $j$ 列目のマスを $(i, j)$ と表します。マス $(i, j)$ には $1 \le A_{i,j} \le (N - K)^2$ を満たす整数 $A_{i,j}$ が書かれています。あなたはこれから以下の操作を順に行います。

  • $N$ 個の行から $K$ 個の行を選び、選んだ行のマスを取り除く。
  • $N$ 個の列から $K$ 個の列を選び、選んだ列のマスを取り除く。

行と列の選び方によっては、残った $(N - K)^2$ 個のマスに書かれた整数がすべて異なることがあります。このような条件を満たす、取り除く行と列の選び方の総数を $998244353$ で割った余りを求めてください。

なお、2 つの選び方が異なるとは、一方の選び方でのみ選ばれる行または列が存在することをいいます。

入力

入力は以下の形式で標準入力から与えられます。

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

制約

  • $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$)
  • 入力される値はすべて整数である。

出力

条件を満たす行と列の選び方の総数を $998244353$ で割った余りを出力してください。

入力例

入力例1

3 1
3 1 4
1 4 2
2 3 1

出力例1

6

入力例2

3 2
1 1 1
1 1 1
1 1 1

出力例2

9

入力例3

6 3
1 7 2 5 6 8
8 9 1 7 5 9
5 2 3 6 4 1
1 2 6 3 9 2
2 4 3 1 5 4
6 9 5 4 2 2

出力例3

10

入出力例の説明

入力例 1 の説明

以下の $6$ 通りの選び方では、残った $(N - K)^2$ 個のマスに書かれた整数が $1, 2, 3, 4$ が 1 個ずつとなるため、条件を満たします。

  • 上から $1$ 行目、左から $1$ 列目を取り除く
  • 上から $1$ 行目、左から $2$ 列目を取り除く
  • 上から $1$ 行目、左から $3$ 列目を取り除く
  • 上から $2$ 行目、左から $3$ 列目を取り除く
  • 上から $3$ 行目、左から $2$ 列目を取り除く
  • 上から $3$ 行目、左から $3$ 列目を取り除く

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1494EditorialOpen题解jianglyView
#1346EditorialOpen题解MilmonView

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.