結果

問題 No.996 Phnom Penh
ユーザー kcvlexkcvlex
提出日時 2020-02-21 23:17:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,978 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 166,408 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 09:18:33
合計ジャッジ時間 2,517 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 WA -
testcase_04 AC 2 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) begin(V), end(V)
#define ALLR(V) rbegin(V), rend(V)
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const ll inf = 5e15;

// 0 : nothing
// 1 : phn
// 2: ph*eh*n
ll jleft(const string &s, ll idx) {
    ll hcnt = 0, ecnt = 0, othcnt = 0;
    ll level = 0;
    for (ll i = idx - 1; !othcnt && 0 <= i; i--) {
        if (s[i] == 'p') {
            if (hcnt == 1 && ecnt == 0) level = 1;
            else if (ecnt == 1 && othcnt == 0) level = 2;
            break;
        } else {
            if (s[i] == 'n') break;
            (s[i] == 'h' ? hcnt : 
             s[i] == 'e' ? ecnt : othcnt)++;
        }
    }
    return level;
}

// 0 : nothing
// 1 : normal
// 2 : h exist
// 3 : e exist
PLL jright(const string &s, ll idx) {
    ll omcnt = 0, hcnt = 0, ecnt = 0, othcnt = 0;
    ll level = 0;
    bool is_o = false;
    for (ll i = idx + 1; !othcnt && i < s.size(); i++) {
        if (s[i] == 'm') {
            if (is_o && !othcnt) {
                is_o = false;
                omcnt++;
                chmax(level, (ll)1);
            } else {
                othcnt++;
            }
        } else if (s[i] == 'o') {
            if (!is_o && !othcnt) {
                is_o = true;
            } else {
                othcnt++;
            }
        } else if (s[i] == 'h') {
            hcnt++;
            if (omcnt < 1) chmax(level, (ll)2);
        } else if (s[i] == 'e') {
            ecnt++;
            if (omcnt < 2) chmax(level, 3 - omcnt);
        } else {
            othcnt++;
            if (s[i] == 'n') break;
        }
    }

    return PLL(level, omcnt);
}

int main() {
    string s;
    cin >> s;
    ll last = 0;
    for (char c : s) {
        if (c == 'h') chmax(last, (ll)1);
        if (c == 'e') chmax(last, (ll)2);
    }

    ll ans = 0;
    ll maxcnt[3] = {};
    for (ll i = 0; i < s.size(); i++) {
        if (s[i] != 'n') continue;
        ll lvl, lvr, omcnt;
        lvl = jleft(s, i);
        tie(lvr, omcnt) = jright(s, i);
        if (lvl == 0) continue;
        if (lvl < lvr) continue;
        ans += omcnt;
        chmax(maxcnt[lvl], omcnt);
    }
    DEBUG(ans);

    {
        ll tmp = 0;
        if (maxcnt[1]) {
            chmax(tmp, maxcnt[1] + 1);
        }
        if (maxcnt[2]) {
            chmax(tmp, maxcnt[2] + 2 - !!maxcnt[1]);
        }
        ans += max<ll>(0, tmp);
    }

    cout << max(ans, last) << endl;
    return 0;
}
0