結果
| 問題 | 
                            No.996 Phnom Penh
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-02-21 22:27:50 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 37 ms / 2,000 ms | 
| コード長 | 1,485 bytes | 
| コンパイル時間 | 2,610 ms | 
| コンパイル使用メモリ | 195,140 KB | 
| 最終ジャッジ日時 | 2025-01-09 01:37:49 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#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++;
                pt += 2;
            }
            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;
}