Editorial for DMPG '19 B3 - Contact


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Kirito

If we have sent at least K consecutive messages, then SSS...SS (which is of length K) will appear as a substring of the input string.

Thus it suffices to check if this string is contained.

Time Complexity: \mathcal O(MK), where M is the total number of messages sent.

This can be optimized to \mathcal O(M + K) by finding the number of consecutive Ss for each prefix. Let P[i] be the smallest index j such that S[j] = S[j + 1] = S[j+2] = \cdots = S[i-1] = S[i] = S. Then P[i+1] = P[i]+1 if S[i] = S, and 0 otherwise. Print Spamming if P[i] \geq K for any i \leq N, and All good otherwise.


Comments

There are no comments at the moment.