#P13694. [CEOI 2025] Splits

    ID: 15529 远端评测题 5000ms 1024MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>2025交互题CEOI(中欧)

[CEOI 2025] Splits

Problem Description

For a permutation p=p[0],p[1],p[2],…,p[n−1]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 A∩B=∅A \cap B = \emptyset, A∪B=0,1,2,…,n−1A \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 T⊆S(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.

3 2
1 2 3
2 1 3
4

Hint

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

  • 1≤n≤3001 \leq n \leq 300
  • 1≤m≤3001 \leq m \leq 300

Subtasks

  1. (6 points) m=1m = 1
  2. (7 points) 1≤n,m≤101 \leq n, m \leq 10
  3. (17 points) 1≤n,m≤181 \leq n, m \leq 18
  4. (17 points) 1≤n≤30,1≤m≤151 \leq n \leq 30, 1 \leq m \leq 15
  5. (16 points) 1≤n,m≤901 \leq n, m \leq 90
  6. (16 points) 1≤n≤300,1≤m≤151 \leq n \leq 300, 1 \leq m \leq 15
  7. (21 points) No additional constraints.