結果

問題 No.996 Phnom Penh
ユーザー chocoruskchocorusk
提出日時 2020-02-21 22:40:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 2,118 bytes
コンパイル時間 1,057 ms
コンパイル使用メモリ 115,260 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 07:51:14
合計ジャッジ時間 1,964 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
P solve(string s){
    int n=s.size();
    bool myon=0, myon1=0;
    for(int i=0; i<n; i++){
        if(s[i]=='h') myon=1;
        else if(s[i]=='e') myon1=1;
    }
    if(!(n>=5 && s.substr(0, 5)=="phnom")){
        if(myon1) return P(0, 2);
        else if(myon) return P(0, 1);
        else return P(0, 0);
    }
    int cnt=1;
    bool b=0;
    for(int i=5; i<n; i++){
        if(!b && s[i]!='h' && s[i]!='e' && s[i]!='o') break;
        if(b && s[i]!='h' && s[i]!='e' && s[i]!='m') break;
        if(cnt==1 && s[i]=='e') break;
        if(s[i]=='o') b=1;
        else if(s[i]=='m'){
            b=0;
            cnt++;
        }
    }
    return P(cnt, cnt+1);
}
int main()
{
    string s; cin>>s;
    int n=s.size();
    bool myon=0, myon1=0;
    vector<int> v1, v2;
    int ans1=0, ans2=0;
    for(int i=0; i<n; i++){
        if(s[i]=='h') myon=1;
        else if(s[i]=='e') myon1=1;
        if(s[i]!='p') continue;
        string t; t+=s[i];
        for(int j=i+1; j<n; j++){
            if(s[j]=='p') break;
            t+=s[j];
        }
        P p1=solve(t);
        if(p1.first>0){
            ans1+=p1.first;
            ans2=max(ans2, p1.second);
            continue;
        }
        string u;
        for(int j=0; j<t.size(); j++){
            if(t[j]=='h') continue;
            u+=t[j];
            if(u.back()=='e') u.back()='h';
        }
        P p2=solve(u);
        ans1+=p2.first;
        ans2=max(ans2, p2.second+1);
    }
    int ans=ans1+ans2;
    if(myon1) ans=max(ans, 2);
    else if(myon) ans=max(ans, 1);
    cout<<ans<<endl;
    return 0;
}
0