#P13012. 【MX-X13-T7】「KDOI-12」No one can be anything without comparison.

    ID: 12527 远端评测题 12000ms 2048MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>O2优化深度优先搜索 DFS树论前缀和分块梦熊比赛

【MX-X13-T7】「KDOI-12」No one can be anything without comparison.

Description

Please note the special constraints on n,k\bm{n,k} in this problem.

nn players participated in kk Tetris Tournaments. Each Tetris Tournament consists of n1n-1 rounds. In each round, two currently uneliminated players xx and yy are selected to compete, and the loser is eliminated. The last remaining player is the winner. You are given that the jj-th player was eliminated by ai,ja_{i,j} in the ii-th Tetris Tournament. Here, jj is the winner of the ii-th tournament if and only if ai,j=0a_{i,j} = 0.

The players enjoy comparison. They all hope to surpass others in some way or at least be on a similar level.

Define that in the ii-th Tetris Tournament, xx strictly dominates yy if and only if there exists a sequence x=p1,p2,,pm=yx = p_1, p_2, \dots, p_m = y (where m2m \ge 2, i.e., xyx \neq y) such that for all 1j<m1 \leq j < m, ai,pj+1=pja_{i,p_{j+1}} = p_j.

An ordered kk-tuple of players (i1,i2,,ik)(i_1, i_2, \dots, i_k) is called level-similar if and only if for all 1j<k1 \leq j < k, iji_j strictly dominates ij+1i_{j+1} in the jj-th tournament, and iki_k strictly dominates i1i_1 in the kk-th tournament.

Your task is to compute the number of level-similar kk-tuples, modulo 998244353998244353.

Input Format

The first line contains two positive integers nn and kk. It is guaranteed that 3k5\bm{3 \leq k \leq 5}.

The next kk lines each contain nn non-negative integers ai,1,,ai,na_{i,1}, \ldots, a_{i,n}, representing the elimination data for the ii-th tournament.

Output Format

Output a single non-negative integer: the number of level-similar kk-tuples, modulo 998244353998244353.

3 3
0 1 2
3 0 2
3 1 0
2
6 5
0 1 1 2 3 4
3 3 0 6 6 1
2 4 1 0 1 1
3 0 2 6 6 2
5 3 6 1 0 4
18

Hint

Sample Explanation #1

The valid 33-tuples (i1,i2,i3)(i_1, i_2, i_3) are: (1,2,3)(1, 2, 3) and (2,3,1)(2, 3, 1).

Constraints

This problem uses bundling tests.

Subtask Points nn\leq k=k= Special Constraints
11 77 100100 33 None
22 88 500500
33 1313 3×1033\times10^3
44 1414 2.5×1052.5\times10^5 A
55 1515 10510^5 B
66 77 None
77 1414 2.5×1052.5\times10^5
88 77 5×1045\times10^4 44
99 66 7.5×1047.5\times10^4
1010 99 4×1044\times10^4 55
  • Special Constraint A: For 1in1 \leq i \leq n, a1,i=a2,ia_{1,i} = a_{2,i}.
  • Special Constraint B: For 1ik1 \leq i \leq k, there do not exist 1j1<j2n1 \leq j_1 < j_2 \leq n such that ai,j1=ai,j2a_{i,j_1} = a_{i,j_2}.

For all test cases:

  • 1n2.5×1051 \leq n \leq 2.5 \times 10^5,
  • 3k5\bm{3 \leq k \leq 5},
  • The aa array is consistent with the problem description, and:
    • If k=3k=3, n2.5×105n \leq 2.5 \times 10^5.
    • If k=4k=4, n7.5×104n \leq 7.5 \times 10^4.
    • If k=5k=5, n4×104n \leq 4 \times 10^4.

Translation by DeepSeek V3.