No.2636 No Waiting in Vain
タグ : / 解いたユーザー数 37
作問者 :
kemuniku
Story (you do not need to read this)
Latte is a person with a lot of free time. He had no particular plans and was just spending one ordinary day after another. However, he takes part in every contest.Deciding to stop idling his time away, he thought as follows:
"Maybe I should plan some wonderful new errands!!!"
Problem Statement
You are given a string $S$ of length $N$, which represents Latte's schedule for $N$ days. The $i\ (1\le i\le N)$-th character $S_i$ of $S$ means the following.
P, a plan is already scheduled on day $i$.C, a contest is scheduled on day $i$.N, nothing is scheduled on day $i$.We also refer to $S_i$ as the schedule of day $i$. Latte has decided to add $1$ or more new plans
P so that the conditions below are satisfied.New plans can only be added on days with $S_i=$
N. On the other days, that is, days with $S_i=$ P, C, no plan can be added.[Conditions]
C then $S_{i+1}\ne$ P holds.N such $i$ is at least $K$.How many ways are there to add plans
P so that all of the above conditions are satisfied? Since the answer can be very large, find it modulo $998244353$.Input
$N\ K$ $S_1S_2\dots S_N$
- $1\le N\le 3\times 10^5$
- $0\le K\le N$
- $|S|=N$
- $S_i$ consists of
P,C,N - $S$ satisfies the conditions in the problem statement. That is,
- for all $i\ (1\le i\le N-1)$, if $S_i=$
Cthen $S_{i+1}\ne$P - for $1\le i\le N$, the number of $S_i=$
Nsuch $i$ is at least $K$
- for all $i\ (1\le i\le N-1)$, if $S_i=$
- $N,K$ are integers
Test case details (you do not need to read this)
This problem has no subtasks, but the constraints differ depending on the case.
small.txt: $1\le N\le 2000$large.txt: No additional constraints.Output
Output the answer.
Sample
Sample 1
Input
5 2 NNCNP
Output
2
We add new plans P, and here we denote those plans by T.
First, if we add $1$ or more new plans P without considering the conditions, there are the following $7(=2^3-1)$ ways.
TNCNPNTCNPNNCTPTTCNPTNCTPNTCTPTTCTPHere, for example,
NNCTP violates "no plan is scheduled on the day after a contest". Also, NTCTP violates "there are at least $K(=2)$ days with nothing scheduled".Removing the ones that violate the conditions in the problem statement in this way leaves
NTCNP and TNCNP, which are $2$ ways. Therefore, the answer is $2$.
Sample 2
Input
3 1 PNC
Output
0
It is impossible to add even $1$ new plan.
Sample 3
Input
10 1 PCNPCNNPCN
Output
1
Only PCNPCNTPCN, that is, adding a plan on day $7$, satisfies the conditions.
Sample 4
Input
9 0 PCCCCCCCN
Output
0
The contest days are consecutive, but this satisfies the conditions in the problem statement. Perhaps Latte likes "contests"...?
Sample 5
Input
29 10 NNCNNNNNPCNNNNNNCNNNNNNCNNNPN
Output
507623
Do not forget to take the remainder modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。