結果

問題 No.996 Phnom Penh
ユーザー neterukunneterukun
提出日時 2020-02-21 23:33:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,124 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 82,504 KB
実行使用メモリ 73,504 KB
最終ジャッジ日時 2024-04-17 09:29:48
合計ジャッジ時間 2,301 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,940 KB
testcase_01 AC 38 ms
53,100 KB
testcase_02 AC 36 ms
52,704 KB
testcase_03 AC 38 ms
53,288 KB
testcase_04 AC 37 ms
53,220 KB
testcase_05 AC 44 ms
62,724 KB
testcase_06 AC 37 ms
53,136 KB
testcase_07 AC 37 ms
54,860 KB
testcase_08 AC 43 ms
60,800 KB
testcase_09 AC 40 ms
60,012 KB
testcase_10 AC 38 ms
52,600 KB
testcase_11 AC 38 ms
53,000 KB
testcase_12 AC 36 ms
52,676 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 37 ms
54,496 KB
testcase_19 AC 36 ms
53,136 KB
testcase_20 AC 37 ms
52,956 KB
testcase_21 AC 35 ms
52,208 KB
testcase_22 AC 36 ms
53,420 KB
testcase_23 AC 37 ms
54,060 KB
testcase_24 AC 56 ms
66,780 KB
testcase_25 AC 54 ms
65,864 KB
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
n = len(s)


ans = 0
flag = False
for i in range(n - 3):
    if s[i:i+4] == "penh":
        flag = True
        tmp = 0
        flag_o = False
        for j in range(i + 4, n):
            if s[j] == "h":
                continue
            if s[j] == "e":
                if tmp >= 1:
                    continue
                else:
                    ans += tmp * 2
                    break
            if s[j] == "o" and not flag_o:
                flag_o = True
                continue
            if s[j] == "m" and flag_o:
                flag_o = False
                tmp += 1
                continue
            else:
                ans += tmp * 2
                break
        else:
            ans += tmp * 2

for i in range(n - 4):
    if s[i:i+5] == "phnom":
        tmp = 0
        flag_o = False
        flag = True
        for j in range(i + 5, n):
            if s[j] == "h":
                continue
            if s[j] == "e":
                if tmp >= 1:
                    continue
                else:
                    ans += tmp * 2 + 1
                    break
            if s[j] == "o" and not flag_o:
                flag_o = True
                continue
            if s[j] == "m" and flag_o:
                flag_o = False
                tmp += 1
                continue
            else:
                ans += tmp * 2 + 1
                break
        else:
            ans += tmp * 2 + 1

if flag:
    ans += 2
if "h" in s:
    ans = max(ans, 1)
if "e" in s:
    ans = max(ans, 2)
if ans == 0:
    print(ans)
    exit()
    
res = ans
ans = 1

s = s.replace("h", "")
s = s.replace("e", "h")
n = len(s)
flag = False
for i in range(n - 3):
    if s[i:i+4] == "penh":
        flag = True
        tmp = 0
        flag_o = False
        for j in range(i + 4, n):
            if s[j] == "h":
                continue
            if s[j] == "e":
                if tmp >= 1:
                    continue
                else:
                    ans += tmp * 2
                    break
            if s[j] == "o" and not flag_o:
                flag_o = True
                continue
            if s[j] == "m" and flag_o:
                flag_o = False
                tmp += 1
                continue
            else:
                ans += tmp * 2
                break
        else:
            ans += tmp * 2

for i in range(n - 4):
    if s[i:i+5] == "phnom":
        tmp = 0
        flag_o = False
        flag = True
        for j in range(i + 5, n):
            if s[j] == "h":
                continue
            if s[j] == "e":
                if tmp >= 1:
                    continue
                else:
                    ans += tmp * 2 + 1
                    break
            if s[j] == "o" and not flag_o:
                flag_o = True
                continue
            if s[j] == "m" and flag_o:
                flag_o = False
                tmp += 1
                continue
            else:
                ans += tmp * 2 + 1
                break
        else:
            ans += tmp * 2 + 1

if flag:
    ans += 2
print(max(res, ans))
0