結果
| 問題 |
No.996 Phnom Penh
|
| コンテスト | |
| ユーザー |
kcvlex
|
| 提出日時 | 2020-02-21 22:49:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,723 bytes |
| コンパイル時間 | 2,256 ms |
| コンパイル使用メモリ | 169,312 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 22:28:51 |
| 合計ジャッジ時間 | 2,888 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 13 |
ソースコード
// #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
// 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;
} 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++;
chmax(level, 2 - omcnt);
} else if (s[i] == 'e') {
ecnt++;
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 cnt = 0;
ll maxcnt = 0;
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 (lvr < lvl) continue;
cnt += omcnt;
DEBUG(lvr);
chmax(maxcnt, omcnt + lvr - 1);
}
DEBUG(cnt, maxcnt);
ll ans = last;
chmax(ans, cnt + maxcnt + 1);
cout << ans << endl;
return 0;
}
kcvlex