CCC '25 J4 - Sunny Days

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2025 Stage 1, Junior #4

There is a large amount of historical weather data for CEMCity. Each day in the data is listed as either a day with sunshine or a day with precipitation. Jeremy is interested in finding the record for the most consecutive days with sunshine. Unfortunately, the data is incorrect for exactly one day, but Jeremy doesn't know which day this is.

Your job is to help Jeremy determine the maximum possible number of consecutive days with sunshine.

Input Specification

The first line of input contains a positive integer, N, representing the number of days in the historical data. The following N lines each contain either the character S or the character P, representing a day with sunshine or a day with precipitation, respectively, in chronological order.

The following table shows how the available 15 marks are distributed:

MarksDescriptionBounds
2There are not many days in the historical data. The data consists of a single block of all S's followed by a single block of all P's. One of these blocks may be empty.N\leq 1\,000
4There are not many days in the historical data. The data contains S's and P's possibly in mixed order.N\leq 1\,000
9There are possibly many days in the historical data.N\leq 500\,000

Output Specification

Output the non-negative integer, M, which is the maximum possible number of consecutive days with sunshine.

Sample Input

8
P
S
P
S
S
P
P
S

Sample Output

4

Explanation for Sample Output

If the data is incorrect for the third day, then there was sunshine from the second day to the fifth day which is four consecutive days with sunshine. This is the maximum possible number of consecutive days with sunshine. That is, no matter which day the data is incorrect for, there were not five (or more) consecutive days of sunshine.


Comments

There are no comments at the moment.