結果

問題 No.996 Phnom Penh
ユーザー yomo3yomo3
提出日時 2020-02-21 23:24:34
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 887 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 815,036 KB
最終ジャッジ日時 2023-07-30 08:07:45
合計ジャッジ時間 4,807 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,844 KB
testcase_01 AC 16 ms
7,904 KB
testcase_02 AC 16 ms
7,844 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 15 ms
7,772 KB
testcase_19 AC 16 ms
7,780 KB
testcase_20 AC 15 ms
7,844 KB
testcase_21 AC 16 ms
7,708 KB
testcase_22 AC 15 ms
7,816 KB
testcase_23 AC 15 ms
7,756 KB
testcase_24 MLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

def D(*a, **kwa):
    print(*a, file=sys.stderr, **kwa)

pm = 'phnom'
ph = 'penh'
can_op1 = lambda s: pm in s
can_op2 = lambda s: 'h' in s or 'e' in s

tr = str.maketrans('e', 'h', 'h')
op1 = lambda s: s.replace(pm, ph)
op2 = lambda s: s.translate(tr)

def solve(op, s, hist):
    if op == 1:
        if can_op1(s):
            s = op1(s)
            hist = hist + '1'
            return solve(2, s, hist)
        else:
            return hist
    else:
        if can_op2(s):
            s = op2(s)
            hist = hist + '2'
            h1 = solve(1, s, hist)
            h2 = '' if hist[-2:] == '22' else solve(2, s, hist)
            return h1 if len(h1) > len(h2) else h2
        else:
            return hist

S = input()

ans = 0
for i in range(1, 2+1):
    hist = solve(i, S, '')
    # D(hist)
    ans = max(ans, len(hist))

print(ans)
0