CF1654H.Three Minimums
普及/提高-
通过率:0%
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,…,pn is good if the following statement holds for all pairs (l,r) with 1≤l<l+2≤r≤n .
- If {pl,pr} are (not necessarily in this order) the first and second minimum of pl,pl+1,…,pr then the third minimum of pl,pl+1,…,pr is either pl+1 or pr−1 .
You are given an integer n and a string s of length m consisting of characters "<" and ">".
Count the number of good permutations p1,p2,…,pn such that, for all 1≤i≤m ,
- pi<pi+1 if si= "<";
- pi>pi+1 if si= ">".
As the result can be very large, you should print it modulo 998244353 .
输入格式
The first line contains two integers n and m ( 2≤n≤2⋅105 , 1≤m≤min(100,n−1) ).
The second line contains a string s of length m , consisting of characters "<" and ">".
输出格式
Print a single integer: the number of good permutations satisfying the constraints described in the statement, modulo 998244353 .
输入输出样例
输入#1
5 3 >>>
输出#1
5
输入#2
5 1 <
输出#2
56
输入#3
6 5 <<><>
输出#3
23
输入#4
10 5 ><<><
输出#4
83154
输入#5
1008 20 <><<>>><<<<<>>>>>>>>
输出#5
284142857
说明/提示
In the first test, there are 5 good permutations satisfying the constraints given by the string s : [4,3,2,1,5] , [5,3,2,1,4] , [5,4,2,1,3] , [5,4,3,1,2] , [5,4,3,2,1] . Each of them
- is good;
- satisfies p1>p2 ;
- satisfies p2>p3 ;
- satisfies p3>p4 .
In the second test, there are 60 permutations such that p1<p2 . Only 56 of them are good: the permutations [1,4,3,5,2] , [1,5,3,4,2] , [2,4,3,5,1] , [2,5,3,4,1] are not good because the required condition doesn't hold for (l,r) = (1,5) . For example, for the permutation [2,4,3,5,1] ,
- the first minimum and the second minimum are p5 and p1 , respectively (so they are {pl,pr} up to reordering);
- the third minimum is p3 (neither pl+1 nor pr−1 ).
In the third test, there are 23 good permutations satisfying the constraints given by the string s : [1,2,4,3,6,5] , [1,2,5,3,6,4] , [1,2,6,3,5,4] , [1,3,4,2,6,5] , [1,3,5,2,6,4] , [1,3,6,2,5,4] , [1,4,5,2,6,3] , [1,4,6,2,5,3] , [1,5,6,2,4,3] , [2,3,4,1,6,5] , [2,3,5,1,6,4] , [2,3,6,1,5,4] , [2,4,5,1,6,3] , [2,4,6,1,5,3] , [2,5,6,1,4,3] , [3,4,5,1,6,2] , [3,4,5,2,6,1] , [3,4,6,1,5,2] , [3,4,6,2,5,1] , [3,5,6,1,4,2] , [3,5,6,2,4,1] , [4,5,6,1,3,2] , [4,5,6,2,3,1] .