Arcadia Computing Contest 2 P2 - Tennis

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Yingchi is practicing tennis for an upcoming tournament. Since he is particularly bad at serving, he decides to focus on his serving technique!

During his practice session, Yingchi serves N times. Each serve results in 3 different outcomes:

  1. S: a successful serve worth 1 point
  2. P: a perfect serve worth 2 points
  3. F: a failed serve worth no points

However, Yingchi, like us, is human and gets nervous under pressure!

  • After making a perfect serve, Yingchi's next serve cannot be perfect
  • After making K consecutive successful or perfect serves, Yingchi's next serve will be a failed serve.

He records his practice session on a piece of paper, but it gets mixed up with someone else's practice logs! Yingchi looks to you to help him determine which practice logs could possibly be his.

Constraints

1KN106

Input Specification

The first line will contain two integers, N and K.

The second line will contain a string of length N consisting of only S, P, and F, denoting the practice log.

Output Specification

If the practice log is possibly Yingchi's, output YES followed by the score of the practice session.

If it could not possibly be Yingchi's, output NO.

Sample Input 1

Copy
8 2
SSFSPFSF

Sample Output 1

Copy
YES
6

Explanation for Sample 1

There are no segments of consecutive S or P with length greater than 2, so it is valid. Then, there are 4 successful serves (worth 4 points) and 1 perfect serve (worth 2 points), for a total of 6 points.

Sample Input 2

Copy
6 2
SPSPSP

Sample Output 2

Copy
NO

Comments

There are no comments at the moment.