結果

問題 No.996 Phnom Penh
ユーザー betrue12betrue12
提出日時 2020-02-21 22:27:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,485 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 196,788 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 07:43:40
合計ジャッジ時間 3,107 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 28 ms
5,376 KB
testcase_14 AC 28 ms
5,376 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 27 ms
5,376 KB
testcase_17 AC 26 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 20 ms
5,376 KB
testcase_25 AC 17 ms
5,376 KB
testcase_26 AC 14 ms
5,376 KB
testcase_27 AC 17 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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++;
                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;
}
0