結果
| 問題 |
No.996 Phnom Penh
|
| コンテスト | |
| ユーザー |
QCFium
|
| 提出日時 | 2020-02-21 22:55:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 2,000 ms |
| コード長 | 1,487 bytes |
| コンパイル時間 | 1,996 ms |
| コンパイル使用メモリ | 172,104 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 22:33:39 |
| 合計ジャッジ時間 | 2,880 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
int64_t rs64() {
int64_t n;
scanf("%" SCNd64, &n);
return n;
}
bool type2(std::string &s) {
int n = s.size();
std::string t;
for (auto c : s) if (c != 'h') t.push_back(c);
std::replace(t.begin(), t.end(), 'e', 'h');
bool res = t != s;
s = t;
return res;
}
// 1, 2
std::pair<int, int> solve(std::string s) {
int r0 = 0, r1 = 0;
while (1) {
while (s.substr(0, 5) != "phnom") {
if (!type2(s)) break;
r1++;
}
if (s.substr(0, 5) != "phnom") break;
r0++;
int index = 5;
int cnt = 0;
while (index + 1 < (int) s.size() && s[index] == 'o' && s[index + 1] == 'm') index += 2, cnt++;
r0 += cnt;
r1 += cnt;
s[0] = 'p';
s[1] = 'E';
s[2] = 'n';
s[3] = 'H';
s.erase(s.begin() + 4, s.begin() + index);
for (int i = 0; i < std::min(2, cnt); i++) type2(s);
s[1] = 'e';
s[3] = 'h';
}
return {r0, r1};
}
int main() {
std::string s;
std::cin >> s;
int n = s.size();
std::vector<std::pair<int, int> > all;
int first = n;
for (int i = 0; i < n; i++) {
if (s[i] == 'p') {
first = std::min(first, i);
int j = i + 1;
for (; j < n && s[j] != 'p'; j++);
all.push_back(solve(s.substr(i, j - i)));
}
}
if (first) {
int cnt = 0;
std::string tmp = s.substr(0, first);
while (type2(tmp)) cnt++;
all.push_back({0, cnt});
}
int res = 0, max = 0;
for (auto &i : all) res += i.first, max = std::max(max, i.second);
printf("%d\n", res + max);
return 0;
}
QCFium