結果
| 問題 | 
                            No.996 Phnom Penh
                             | 
                    
| コンテスト | |
| ユーザー | 
                             QCFium
                         | 
                    
| 提出日時 | 2020-02-21 22:22:40 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 956 bytes | 
| コンパイル時間 | 1,550 ms | 
| コンパイル使用メモリ | 170,828 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-08 21:54:51 | 
| 合計ジャッジ時間 | 2,440 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 18 WA * 7 | 
ソースコード
#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');
	if (t != s) res = std::max(res, solve(t) + 1);
	printf("%d\n", res);
	return 0;
}
            
            
            
        
            
QCFium