CF1654H.Three Minimums

NOI/NOI+/CTSC

通过率:0%

时间限制:8.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given a list of distinct values, we denote with first minimum, second minimum, and third minimum the three smallest values (in increasing order).

A permutation p1,p2,…,pnp_1, p_2, \dots, p_n is good if the following statement holds for all pairs (l,r)(l,r) with 1≤l<l+2≤r≤n1\le l \lt l+2 \le r\le n.

  • If pl,pr{p_l, p_r} are (not necessarily in this order) the first and second minimum of pl,pl+1,…,prp_l, p_{l+1}, \dots, p_r then the third minimum of pl,pl+1,…,prp_l, p_{l+1},\dots, p_r is either pl+1p_{l+1} or pr−1p_{r-1}.

You are given an integer nn and a string ss of length mm consisting of characters "<" and ">".

Count the number of good permutations p1,p2,…,pnp_1, p_2,\dots, p_n such that, for all 1≤i≤m1\le i\le m,

  • pi<pi+1p_i \lt p_{i+1} if si=s_i = "<";
  • pi>pi+1p_i \gt p_{i+1} if si=s_i = ">".

As the result can be very large, you should print it modulo 998 244 353998\,244\,353.

给定一个由互不相同元素构成的列表,我们用“第一小值”、“第二小值”和“第三小值”分别表示该列表中三个最小的值(按升序排列)。

排列 p1,p2,…,pnp_1, p_2, \dots, p_n 称为好排列,当且仅当对所有满足 1≤l<l+2≤r≤n1\le l < l+2 \le r\le n 的数对 (l,r)(l,r),如下命题成立:

  • 若 {pl,pr}\{p_l, p_r\}(顺序不限)恰好是子数组 pl,pl+1,…,prp_l, p_{l+1}, \dots, p_r 中的第一小值与第二小值,则该子数组的第三小值必为 pl+1p_{l+1} 或 pr−1p_{r-1}。

现给定一个整数 nn 和一个长度为 mm 的字符串 ss,其中每个字符为 “<” 或 “>”。

请计算满足如下条件的好排列 p1,p2,…,pnp_1, p_2,\dots, p_n 的个数:

  • 对每个 1≤i≤m1\le i\le m,
    • 若 si=s_i = “<”,则 pi<pi+1p_i < p_{i+1};
    • 若 si=s_i = “>”,则 pi>pi+1p_i > p_{i+1}。

由于答案可能非常大,请将结果对 998 244 353998\,244\,353 取模后输出。

输入格式

The first line contains two integers nn and mm (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, 1≤m≤min⁡(100,n−1)1 \leq m \leq \min(100, n-1)).

The second line contains a string ss of length mm, consisting of characters "<" and ">".

第一行包含两个整数 nn 和 mm(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,1≤m≤min⁡(100,n−1)1 \leq m \leq \min(100, n-1))。

第二行包含一个长度为 mm 的字符串 ss,由字符 "<" 和 ">" 组成。

输出格式

Print a single integer: the number of good permutations satisfying the constraints described in the statement, modulo 998 244 353998\,244\,353.

输出一个整数:满足题目描述中约束条件的“好”排列的数量,对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    5 3
    &gt;&gt;&gt;

    输出#1

    5
  • 输入#2

    5 1
    &lt;

    输出#2

    56
  • 输入#3

    6 5
    &lt;&lt;&gt;&lt;&gt;

    输出#3

    23
  • 输入#4

    10 5
    &gt;&lt;&lt;&gt;&lt;

    输出#4

    83154
  • 输入#5

    1008 20
    &lt;&gt;&lt;&lt;&gt;&gt;&gt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;

    输出#5

    284142857

说明/提示

In the first test, there are 55 good permutations satisfying the constraints given by the string ss: [4,3,2,1,5][4, 3, 2, 1, 5], [5,3,2,1,4][5, 3, 2, 1, 4], [5,4,2,1,3][5, 4, 2, 1, 3], [5,4,3,1,2][5, 4, 3, 1, 2], [5,4,3,2,1][5, 4, 3, 2, 1]. Each of them

  • is good;
  • satisfies p1>p2p_1 \gt p_2;
  • satisfies p2>p3p_2 \gt p_3;
  • satisfies p3>p4p_3 \gt p_4.

In the second test, there are 6060 permutations such that p1<p2p_1 \lt p_2. Only 5656 of them are good: the permutations [1,4,3,5,2][1, 4, 3, 5, 2], [1,5,3,4,2][1, 5, 3, 4, 2], [2,4,3,5,1][2, 4, 3, 5, 1], [2,5,3,4,1][2, 5, 3, 4, 1] are not good because the required condition doesn't hold for (l,r)(l, r) = (1,5)(1, 5). For example, for the permutation [2,4,3,5,1][2, 4, 3, 5, 1],

  • the first minimum and the second minimum are p5p_5 and p1p_1, respectively (so they are pl,pr{p_l, p_r} up to reordering);
  • the third minimum is p3p_3 (neither pl+1p_{l+1} nor pr−1p_{r-1}).

In the third test, there are 2323 good permutations satisfying the constraints given by the string ss: [1,2,4,3,6,5][1, 2, 4, 3, 6, 5], [1,2,5,3,6,4][1, 2, 5, 3, 6, 4], [1,2,6,3,5,4][1, 2, 6, 3, 5, 4], [1,3,4,2,6,5][1, 3, 4, 2, 6, 5], [1,3,5,2,6,4][1, 3, 5, 2, 6, 4], [1,3,6,2,5,4][1, 3, 6, 2, 5, 4], [1,4,5,2,6,3][1, 4, 5, 2, 6, 3], [1,4,6,2,5,3][1, 4, 6, 2, 5, 3], [1,5,6,2,4,3][1, 5, 6, 2, 4, 3], [2,3,4,1,6,5][2, 3, 4, 1, 6, 5], [2,3,5,1,6,4][2, 3, 5, 1, 6, 4], [2,3,6,1,5,4][2, 3, 6, 1, 5, 4], [2,4,5,1,6,3][2, 4, 5, 1, 6, 3], [2,4,6,1,5,3][2, 4, 6, 1, 5, 3], [2,5,6,1,4,3][2, 5, 6, 1, 4, 3], [3,4,5,1,6,2][3, 4, 5, 1, 6, 2], [3,4,5,2,6,1][3, 4, 5, 2, 6, 1], [3,4,6,1,5,2][3, 4, 6, 1, 5, 2], [3,4,6,2,5,1][3, 4, 6, 2, 5, 1], [3,5,6,1,4,2][3, 5, 6, 1, 4, 2], [3,5,6,2,4,1][3, 5, 6, 2, 4, 1], [4,5,6,1,3,2][4, 5, 6, 1, 3, 2], [4,5,6,2,3,1][4, 5, 6, 2, 3, 1].

在第一个测试用例中,有 55 个满足字符串 ss 所给约束条件的“好”排列:[4,3,2,1,5][4, 3, 2, 1, 5]、[5,3,2,1,4][5, 3, 2, 1, 4]、[5,4,2,1,3][5, 4, 2, 1, 3]、[5,4,3,1,2][5, 4, 3, 1, 2]、[5,4,3,2,1][5, 4, 3, 2, 1]。它们均

  • 是“好”的;
  • 满足 p1>p2p_1 \gt p_2;
  • 满足 p2>p3p_2 \gt p_3;
  • 满足 p3>p4p_3 \gt p_4。

在第二个测试用例中,共有 6060 个满足 p1<p2p_1 \lt p_2 的排列;其中仅有 5656 个是“好”的:排列 [1,4,3,5,2][1, 4, 3, 5, 2]、[1,5,3,4,2][1, 5, 3, 4, 2]、[2,4,3,5,1][2, 4, 3, 5, 1]、[2,5,3,4,1][2, 5, 3, 4, 1] 不是“好”的,因为对 (l,r)=(1,5)(l, r) = (1, 5) 这一区间,所要求的条件不成立。例如,对于排列 [2,4,3,5,1][2, 4, 3, 5, 1],

  • 第一小值与第二小值分别为 p5p_5 和 p1p_1(因此它们恰好是 {pl,pr}\{p_l, p_r\},顺序可交换);
  • 第三小值为 p3p_3(既不是 pl+1p_{l+1},也不是 pr−1p_{r-1})。

在第三个测试用例中,有 2323 个满足字符串 ss 所给约束条件的“好”排列:[1,2,4,3,6,5][1, 2, 4, 3, 6, 5]、[1,2,5,3,6,4][1, 2, 5, 3, 6, 4]、[1,2,6,3,5,4][1, 2, 6, 3, 5, 4]、[1,3,4,2,6,5][1, 3, 4, 2, 6, 5]、[1,3,5,2,6,4][1, 3, 5, 2, 6, 4]、[1,3,6,2,5,4][1, 3, 6, 2, 5, 4]、[1,4,5,2,6,3][1, 4, 5, 2, 6, 3]、[1,4,6,2,5,3][1, 4, 6, 2, 5, 3]、[1,5,6,2,4,3][1, 5, 6, 2, 4, 3]、[2,3,4,1,6,5][2, 3, 4, 1, 6, 5]、[2,3,5,1,6,4][2, 3, 5, 1, 6, 4]、[2,3,6,1,5,4][2, 3, 6, 1, 5, 4]、[2,4,5,1,6,3][2, 4, 5, 1, 6, 3]、[2,4,6,1,5,3][2, 4, 6, 1, 5, 3]、[2,5,6,1,4,3][2, 5, 6, 1, 4, 3]、[3,4,5,1,6,2][3, 4, 5, 1, 6, 2]、[3,4,5,2,6,1][3, 4, 5, 2, 6, 1]、[3,4,6,1,5,2][3, 4, 6, 1, 5, 2]、[3,4,6,2,5,1][3, 4, 6, 2, 5, 1]、[3,5,6,1,4,2][3, 5, 6, 1, 4, 2]、[3,5,6,2,4,1][3, 5, 6, 2, 4, 1]、[4,5,6,1,3,2][4, 5, 6, 1, 3, 2]、[4,5,6,2,3,1][4, 5, 6, 2, 3, 1]。

输入解题思路,AI测评打分。不知道怎么写?

首页