No.1534 My Stomach Hurts
Problem Statement
Right now, Yuyu has a terrible stomachache. Trying to post about it on social media, Yuyu typed ponponpain.
However, Yuyu then decided that this was not a pain that could be expressed in a mere 10 characters, and chose to use an indicator that expresses the stomach pain by the number of pon.
The "pain index", the indicator devised by Yuyu, is defined as follows.
- The value of the pain index is a positive integer.
- If exactly 2 occurrences of
ponare contained to the left of the leftmostpain, counting from the beginning of the string, the pain index is 1. - When 2 or more occurrences of
ponare contained to the left of the leftmostpain, the pain index increases by 1 each time the number ofponincreases by 1.
-1.
- When
painis not contained. - When the number of
poncontained between the beginning of the string and the leftmostpainis less than 2.
For example, when
ponponponponpain is posted, the stomach pain index is 3.Given the posted string $S$, find Yuyu's stomach pain index. [Added at 18:05] A substring here means a contiguous substring.
Input
$S$
- The length of the string is at most $2 \times 10^5$ characters.
- A string of lowercase English letters is given on one line.
- [Added at 18:10] The length of the string is at least $1$ character.
Output
Print a newline at the end.
Sample
Sample 1
Input
ponponponponponpain
Output
4
Sample 2
Input
ponnpooponpomponpainponponponpain
Output
2
The string has pom and npoo mixed in, but these are not reflected in the pain index.
Also, even when pain is contained 2 or more times, the characters at and after the leftmost pain of the received string are not reflected in the pain index either.
Sample 3
Input
ponponponpaim
Output
-1
It seems the stomach does not actually hurt. If pain is not contained as a substring, output -1.
Sample 4
Input
ponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponpomponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponponpain
Output
90
The stomach seems to hurt very badly. I hope everything is okay.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
57tggx
logx
Re_menal2
とりゐ