#P13694. [CEOI 2025] Splits

[CEOI 2025] Splits

题目描述

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,,ikA = i_1, i_2, \ldots, i_k and B=j1,j2,,jlB = j_1, j_2, \ldots, j_l such that AB=A \cap B = \emptyset, AB=0,1,2,,n1A \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 998244353998\,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 998244353998\,244\,353. This procedure is called exactly once for each test case.

3 2
1 2 3
2 1 3
4

提示

Sample Explanation 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:

  • 123123
  • 213213

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

  • 123123
  • 132132
  • 213213
  • 231231

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.