結果
| 問題 |
No.996 Phnom Penh
|
| コンテスト | |
| ユーザー |
QCFium
|
| 提出日時 | 2020-02-21 22:21:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 944 bytes |
| コンパイル時間 | 1,777 ms |
| コンパイル使用メモリ | 171,796 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-08 21:54:08 |
| 合計ジャッジ時間 | 2,784 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 8 |
ソースコード
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
int64_t rs64() {
int64_t n;
scanf("%" SCNd64, &n);
return n;
}
int solve(const std::string &s) {
int n = s.size();
std::vector<int> all;
for (int i = 0; i + 4 < n; i++) {
if (s.substr(i, 5) == "phnom") {
all.push_back(0);
i += 5;
while (i + 1 < n && s[i] == 'o' && s[i + 1] == 'm') i += 2, all.back()++;
i--;
}
}
if (all.size()) return std::accumulate(all.begin(), all.end(), 0) + *std::max_element(all.begin(), all.end()) + all.size() + 2;
else if (std::count(s.begin(), s.end(), 'e')) return 2;
else if (std::count(s.begin(), s.end(), 'h')) return 1;
else return 0;
}
int main() {
std::string s;
std::cin >> s;
int n = s.size();
int res = solve(s);
std::string t;
for (auto c : s) if (c != 'h') t.push_back(c);
std::replace(t.begin(), t.end(), 'e', 'h');
res = std::max(res, solve(t) + 1);
printf("%d\n", res);
return 0;
}
QCFium