結果

問題 No.996 Phnom Penh
ユーザー betrue12betrue12
提出日時 2020-02-21 22:27:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,485 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 199,716 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-30 05:56:58
合計ジャッジ時間 3,623 ms
ジャッジサーバーID
(参考情報)
judge5 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 45 ms
4,376 KB
testcase_14 AC 46 ms
4,384 KB
testcase_15 AC 45 ms
4,376 KB
testcase_16 AC 45 ms
4,380 KB
testcase_17 AC 45 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 34 ms
4,380 KB
testcase_25 AC 28 ms
4,380 KB
testcase_26 AC 21 ms
4,380 KB
testcase_27 AC 27 ms
4,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