#P12506. 「CEOI2025」分割

「CEOI2025」分割

Description

For a permutation p=p[0] p[1] p[2]  p[n1]p = p[0]\ p[1]\ p[2]\ \ldots\ p[n-1] of the numbers 1,2,3,,n1, 2, 3, \ldots, n we define a split as a permutation qq which can be obtained by the following process:

  1. Select two sets of numbers A={i1,i2,...,ik}A = \{i_1, i_2, ..., i_k\} and B={j1,j2,...,jl}B = \{j_1, j_2, ..., j_l\} such that AB=A \cap B = \varnothing, AB={0,1,2,,n1}A \cup B = \{0, 1, 2, \ldots, n-1\}, i1<i2<<iki_1 < i_2 < \ldots < i_k and j1<j2<<jlj_1 < j_2 < \ldots < j_l.

  2. The permutation qq will be $q = p[i_1]p[i_2]\ldots p[i_k]p[j_1]p[j_2]\ldots p[j_l]$.

Moreover, we define S(p)S(p) to be the set of all splits of a permutation pp.

You are given a number nn and a set TT of mm permutations of length nn. Count how many permutations pp of length nn exist such that TS(p)T \subseteq S(p). Since this number can be large, find it modulo 998 244 353998\ 244\ 353.

Implementation Details

You should implement the following procedure:

int solve(int n, int m, std::vector<std::vector<int>>& splits);
  • nn: the size of the permutation
  • mm: the number of splits
  • splitssplits: array containing mm pairwise distinct permutations, the elements of the set TT, which is a subset of S(p)S(p)
  • This procedure should return the number of possible permutations modulo 998 244 353998\ 244\ 353.
  • This procedure is called exactly once for each test case.

Constraints

  • 1n3001 \leq n \leq 300
  • 1m3001 \leq m \leq 300

Subtasks

  1. (6 points) m=1m = 1
  2. (7 points) 1n,m101 \leq n, m \leq 10
  3. (17 points) 1n,m181 \leq n, m \leq 18
  4. (17 points) 1n30, 1m151 \leq n \leq 30,\ 1 \leq m \leq 15
  5. (16 points) 1n,m901 \leq n, m \leq 90
  6. (16 points) 1n300, 1m151 \leq n \leq 300,\ 1 \leq m \leq 15
  7. (21 points) No additional constraints.

Example 1

Consider the following call:

solve(3, 2, {{1, 2, 3}, {2, 1, 3}})

In this sample, the size of the permutation pp is 33 and we are given 22 splits:

  • 1 2 31\ 2\ 3
  • 2 1 32\ 1\ 3

The function call will return 44 as there are only four permutations pp that can generate both of those splits:

  • 1 2 31\ 2\ 3
  • 1 3 21\ 3\ 2
  • 2 1 32\ 1\ 3
  • 2 3 12\ 3\ 1

Sample grader

The sample grader reads the input in the following format:

  • line 11: n mn\ m
  • line 2+i2 + i: s[i][0] s[i][1]  s[i][n1]s[i][0]\ s[i][1]\ \ldots\ s[i][n-1] for all 0i<m0 \leq i < m

and outputs the result of the call to solve with the corresponding parameters.