結果
| 問題 |
No.996 Phnom Penh
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2020-02-22 16:00:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 2,647 bytes |
| コンパイル時間 | 2,369 ms |
| コンパイル使用メモリ | 199,788 KB |
| 最終ジャッジ日時 | 2025-01-09 01:51:48 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
string S;
//---------------------------------------------------------------------------------------------------
pair<string, int> ope1(string s) {
int cnt = 0;
string res = "";
int n = s.length();
rep(i, 0, n) {
if (i + 5 <= n && s.substr(i, 5) == "phnom") {
cnt++;
res += "penh";
i += 4;
}
else res += s[i];
}
return { res, cnt };
}
pair<string,int> ope2(string s) {
int cnt = 0;
string res = "";
fore(c, s) {
if (c == 'h') cnt = 1;
else res += c;
}
fore(c, res) if (c == 'e') {
c = 'h';
cnt = 1;
}
return { res, cnt };
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> S;
int ans = 0;
rep(i, 0, 2) {
int tot = 0, res;
string s = S;
if (i == 0) tie(s, tot) = ope2(s);
rep(_, 0, 5) {
int res;
tie(s, res) = ope1(s);
tot += res;
tie(s, res) = ope2(s);
tot += res;
}
int n = s.length();
int ma = 0;
rep(i, 0, n - 4) if (s.substr(i, 5) == "phnom") {
int cnt = 0;
int j = i + 3;
while (j < n - 1) {
if (s.substr(j, 2) != "om") break;
cnt++;
j += 2;
}
chmax(ma, cnt);
tot += cnt;
}
if (ma == 0) {
tie(s, res) = ope2(s);
tot += res;
} else tot += ma + 1;
chmax(ans, tot);
}
cout << ans << endl;
}
はまやんはまやん