結果

問題 No.996 Phnom Penh
ユーザー maspymaspy
提出日時 2020-04-08 15:37:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-07-18 13:26:36
合計ジャッジ時間 1,931 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode().replace('p', ' p')


def solve(S):
    op1 = 0
    op2 = 0
    for _ in range(3):
        if S[:5] == 'phnom':
            S = S.replace('phnom', 'penh')
            op1 += 1
        T = S.replace('h', '').replace('e', 'h')
        if S == T:
            return op1, op2
        S = T
        op2 += 1
    assert not S.count('e')
    if not S.startswith('phn'):
        if S.count('h'):
            return op1, op2 + 1
        else:
            return op1, op2
    # phn + om * k -> phn
    S = S[3:].replace('om', 'X')
    k = 0
    for i, x in enumerate(S):
        if x == 'X':
            k += 1
        else:
            break
    return op1 + k, op2 + k + 1


op1 = 0
op2 = 0
for x, y in map(solve, S.replace('p', ' p').split()):
    op1 += x
    if op2 < y:
        op2 = y
print(op1 + op2)
0