問題一覧 > 通常問題

No.1534 My Stomach Hurts

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 144
作問者 : ゅゅ / テスター : 57tggx logx 👑 qand Re_menal2 とりゐ
お気に入りにしたユーザー ProblemId : 6099 / 自分の提出
問題文最終更新日: 2021-06-06 18:10:57
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
ゅゅちゃんお誕生日コンテスト (順位表) の他の問題:

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 pon are contained to the left of the leftmost pain, counting from the beginning of the string, the pain index is 1.
  • When 2 or more occurrences of pon are contained to the left of the leftmost pain, the pain index increases by 1 each time the number of pon increases by 1.
However, the pain index is considered undefined in the following cases. In these cases, output -1.
  • When pain is not contained.
  • When the number of pon contained between the beginning of the string and the leftmost pain is less than 2.
In the above, a string $S$ containing a string $T$ means that $T$ appears as a substring of $S$.
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もしくは右上の雲マークをクリックしてアカウントを作成してください。