結果

問題 No.996 Phnom Penh
ユーザー yomo3yomo3
提出日時 2020-02-21 23:09:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 109,184 KB
最終ジャッジ日時 2024-04-17 09:13:47
合計ジャッジ時間 2,087 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,624 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 29 ms
10,624 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 27 ms
10,624 KB
testcase_19 AC 29 ms
10,624 KB
testcase_20 AC 29 ms
10,752 KB
testcase_21 AC 29 ms
10,624 KB
testcase_22 AC 29 ms
10,752 KB
testcase_23 AC 28 ms
10,624 KB
testcase_24 RE -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

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 = 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