結果

問題 No.996 Phnom Penh
ユーザー 👑 tamatotamato
提出日時 2020-02-21 23:10:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 2,080 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 97,152 KB
最終ジャッジ日時 2024-04-17 09:13:55
合計ジャッジ時間 3,308 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,968 KB
testcase_01 AC 42 ms
51,968 KB
testcase_02 AC 41 ms
51,968 KB
testcase_03 AC 50 ms
59,264 KB
testcase_04 AC 44 ms
52,480 KB
testcase_05 AC 59 ms
63,488 KB
testcase_06 AC 41 ms
52,096 KB
testcase_07 AC 48 ms
59,392 KB
testcase_08 AC 59 ms
62,976 KB
testcase_09 AC 57 ms
62,592 KB
testcase_10 AC 42 ms
51,840 KB
testcase_11 AC 51 ms
59,648 KB
testcase_12 AC 49 ms
59,136 KB
testcase_13 AC 135 ms
95,488 KB
testcase_14 AC 133 ms
95,872 KB
testcase_15 AC 131 ms
96,128 KB
testcase_16 AC 134 ms
95,616 KB
testcase_17 AC 131 ms
95,488 KB
testcase_18 AC 41 ms
51,968 KB
testcase_19 AC 39 ms
51,712 KB
testcase_20 AC 42 ms
52,096 KB
testcase_21 AC 42 ms
51,840 KB
testcase_22 AC 42 ms
51,840 KB
testcase_23 AC 42 ms
51,712 KB
testcase_24 AC 113 ms
96,896 KB
testcase_25 AC 118 ms
96,896 KB
testcase_26 AC 133 ms
97,152 KB
testcase_27 AC 113 ms
95,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.readline

    S = [s for s in input().rstrip('\n')]
    phnom = 'phnom'
    penh = 'penh'
    penhx = 'penh!'
    ans = 0
    for i in range(len(S) - 4):
        flg = 1
        for j in range(5):
            if S[i+j] != phnom[j]:
                flg = 0
        if flg:
            ans += 1
            for j in range(5):
                S[i+j] = penhx[j]
    if 'h' not in S and 'e' not in S:
        print(ans)
        exit()
    S_new = []
    ans += 1
    for s in S:
        if s == '!' or s == 'h':
            continue
        if s == 'e':
            S_new.append('h')
        else:
            S_new.append(s)
    S_new.append('!')
    flg = 0
    has_phnom = 0
    #print(ans)
    #print(S_new)
    n = len(S_new)
    i = 0
    om_num_max = 0
    while i < n:
        #print(flg, i)
        if flg == 0:
            if i+2 < n:
                ok = 1
                for j in range(3):
                    if S_new[i+j] != phnom[j]:
                        ok = 0
            else:
                ok = 0
            if ok:
                has_phnom = 1
                flg = 1
                i += 3
                om_num = 0
            else:
                i += 1
        elif flg == 1:
            if S_new[i] == 'o':
                flg = 2
                i += 1
            elif S_new[i] == 'h' and om_num > 0:
                i += 1
            else:
                om_num_max = max(om_num_max, om_num)
                ans += om_num
                flg = 0
        elif flg == 2:
            if S_new[i] == 'm':
                om_num += 1
                flg = 1
                i += 1
            elif S_new[i] == 'h' and om_num > 0:
                i += 1
            else:
                om_num_max = max(om_num_max, om_num)
                ans += om_num
                flg = 0
    if not has_phnom:
        if 'e' in S_new:
            ans += 2
        elif 'h' in S_new:
            ans += 1
    else:
        ans += 1
        ans += om_num_max
    print(ans)


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