結果

問題 No.996 Phnom Penh
ユーザー mamekinmamekin
提出日時 2020-02-24 15:20:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,820 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 117,296 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 10:28:10
合計ジャッジ時間 3,128 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int solve1(string& s)
{
    int n = s.size();
    int i = 0;
    int ans = 0;
    string t;
    while(i < n){
        if(s.substr(i, 5) == "phnom"){
            t += "penh";
            i += 5;
            ++ ans;
        }
        else{
            t += s[i];
            ++ i;
        }
    }
    s = move(t);
    return ans;
}

int solve2(string& s)
{
    if(s.find('h') == string::npos && s.find('e') == string::npos)
        return 0;

    int n = s.size();
    string t;
    for(int i=0; i<n; ++i){
        if(s[i] != 'h'){
            if(s[i] == 'e')
                t += 'h';
            else
                t += s[i];
        }
    }
    s = move(t);
    return 1;
}

int main()
{
    string s;
    cin >> s;

    int ans = 0;
    for(int i=0; i<2; ++i){
        ans += solve1(s);
        ans += solve2(s);
    }

    int n = s.size();
    int maxLen = (s.find('h') == string::npos)? 0 : 1;
    int i = 0;
    while(i < n){
        if(s.substr(i, 5) == "phnom"){
            i += 5;
            int len = 1;
            while(i < n && s.substr(i, 2) == "om"){
                i += 2;
                ++ len;
            }
            ans += len;
            maxLen = max(maxLen, len + 1);
        }
        else{
            ++ i;
        }
    }
    ans += maxLen;
    cout << ans << endl;

    return 0;
}
0