結果

問題 No.1534 おなかがいたい
ユーザー lloyz
提出日時 2021-12-21 22:43:35
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 542 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-09-15 15:40:12
合計ジャッジ時間 2,238 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
n = len(S)

pon = "pon"
pon_ind = 0
pain = "pain"
pain_ind = 0
cnt = 0
for i in range(n):
    if S[i] == pon[pon_ind]:
        pon_ind += 1
        if pon_ind == 3:
            cnt += 1
            pon_ind = 0
    elif pon_ind > 0:
        pon_ind = 0
    if S[i] == pain[pain_ind]:
        pain_ind += 1
        if pain_ind == 4:
            if cnt < 2:
                print(-1)
            else:
                print(cnt - 1)
            exit()
    elif pain_ind > 0:
        pain_ind = 0
print(-1)
0