結果

問題 No.996 Phnom Penh
ユーザー betrue12
提出日時 2020-02-21 22:25:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,460 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 195,676 KB
最終ジャッジ日時 2025-01-09 01:37:21
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    string S;
    cin >> S;
    int64_t ans = 0;
    for(int t=0; t<10; t++){
        int N = S.size();
        int pt = 0;
        string T, U;
        while(pt < N){
            if(S.substr(pt, 5) == "phnom"){
                T.append("penh");
                pt += 5;
                ans++;
            }else{
                T.push_back(S[pt]);
                pt++;
            }
        }
        bool found = false;
        for(char c : T){
            if(c == 'h'){
                found = true;
            }else if(c == 'e'){
                found = true;
                U.push_back('h');
            }else{
                U.push_back(c);
            }
        }
        if(found) ans++;
        S = U;
    }

    int mx = 0;
    int pt = 0, N = S.size();
    while(pt < N){
        bool found = false;
        if(S.substr(pt, 5) == "phnom"){
            found = true;
            ans++;
            pt += 5;
        }else if(S.substr(pt, 4) == "penh"){
            found = true;
            pt += 4;
        }
        if(found){
            int num = 0;
            while(S.substr(pt, 2) == "om"){
                num++;
                ans++;
            }
            mx = max(mx, num+2);
        }else{
            if(S[pt] == 'h') mx = max(mx, 1);
            if(S[pt] == 'e') mx = max(mx, 2);
            pt++;
        }
    }
    ans += mx;
    cout << ans << endl;
    return 0;
}
0