結果

問題 No.1534 おなかがいたい
ユーザー ygd.ygd.
提出日時 2021-06-09 21:00:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 633 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 9,940 KB
最終ジャッジ日時 2023-08-19 07:02:17
合計ジャッジ時間 2,029 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,960 KB
testcase_01 AC 15 ms
7,808 KB
testcase_02 AC 15 ms
8,008 KB
testcase_03 AC 15 ms
7,808 KB
testcase_04 AC 14 ms
7,792 KB
testcase_05 AC 14 ms
7,956 KB
testcase_06 AC 15 ms
8,052 KB
testcase_07 AC 14 ms
7,820 KB
testcase_08 AC 14 ms
7,804 KB
testcase_09 AC 14 ms
7,912 KB
testcase_10 AC 13 ms
8,016 KB
testcase_11 AC 14 ms
7,964 KB
testcase_12 AC 70 ms
9,804 KB
testcase_13 AC 60 ms
9,856 KB
testcase_14 AC 59 ms
9,848 KB
testcase_15 AC 14 ms
8,396 KB
testcase_16 AC 80 ms
9,792 KB
testcase_17 AC 83 ms
9,932 KB
testcase_18 AC 80 ms
9,940 KB
testcase_19 AC 14 ms
8,344 KB
testcase_20 AC 83 ms
9,792 KB
testcase_21 AC 16 ms
7,852 KB
testcase_22 AC 15 ms
7,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    s = str(input())
    n = len(s)
    stack = []
    Flag = 0
    for i in range(n):
        if i+4 <= n and s[i:i+4] == "pain":
            Flag = 1
            break
        else:
            stack.append(s[i])
    #print(stack)
    if Flag == 0:
        print(-1);exit()
    ans = 0
    while len(stack) >= 3:
        if stack[-3] == "p" and stack[-2] == "o" and stack[-1] == "n":
            ans += 1
            stack.pop()
            stack.pop()
            stack.pop()
        else:
            stack.pop()
    if ans >= 2:
        print(ans-1)
    else:
        print(-1)

if __name__ == '__main__':
    main()
0